uploading a file to a server.

181 views
Skip to first unread message

Marty Amberg

unread,
Apr 22, 2012, 7:54:45 PM4/22/12
to prototype-s...@googlegroups.com
Hi all,

Quick question.
I been trying to get a file to upload to a server via a form ( works
great in straight html calling a php program ) using a prototype ajax
request. I don't think it can be done and I have tried various
ways. If I am wrong and could some one point me in the right directions.

Thanks




--
EdenStreet Consulting
w:978-741-7518
c:978-821-1309
Twitter: martyateden
Skype: martyateden

Miguel Beltran R.

unread,
Apr 23, 2012, 10:31:17 AM4/23/12
to prototype-s...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to prototype-scriptaculous+unsub...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.




--
________________________________________
Lo bueno de vivir un dia mas
es saber que nos queda un dia menos de vida

Marty Amberg

unread,
Apr 23, 2012, 10:38:33 AM4/23/12
to prototype-s...@googlegroups.com
Thanks Miguel.

 I did lot of searches but the  answers saying no always seem to have some other answers claiming there was a way.  Nothing I tried worked henceforth the question.   I  am happy to do it in straight php. 

On 4/23/2012 10:31 AM, Miguel Beltran R. wrote:
Hi all,

Quick question.
I been trying to get a file to upload to  a server via a form ( works great in straight html calling a php program ) using a  prototype ajax request.  I  don't think it can be done and I have tried various ways.    If I am wrong and  could some one point me in the right directions.

Thanks





--
EdenStreet Consulting
w:978-741-7518
c:978-821-1309
Twitter: martyateden
Skype: martyateden

--
You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group.
To post to this group, send email to prototype-s...@googlegroups.com.
To unsubscribe from this group, send email to prototype-scripta...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.




--
________________________________________
Lo bueno de vivir un dia mas
es saber que nos queda un dia menos de vida
--
You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group.
To post to this group, send email to prototype-s...@googlegroups.com.
To unsubscribe from this group, send email to prototype-scripta...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.

-- 
EdenStreet Consulting
w:978-741-7518

Jason

unread,
May 13, 2012, 12:32:45 AM5/13/12
to prototype-s...@googlegroups.com

Totally do-able using the HTML 5 Javascript File API (won't work in IE though)

you can use the file object in the postBody option and that will upload the file to your php script through the php://input stream - use $_GET parameters for the rest of the information you want to post


to solve the IE problem chromeframe is a good solution as well

I can post an example if you need

Jason

Marty Amberg

unread,
May 16, 2012, 2:48:14 PM5/16/12
to prototype-s...@googlegroups.com
Thanks Jason

Will give it a shot.  A example would be great,
--
You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group.

To post to this group, send email to prototype-s...@googlegroups.com.
To unsubscribe from this group, send email to prototype-scripta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.

Jason Westbrook

unread,
May 16, 2012, 6:07:20 PM5/16/12
to prototype-s...@googlegroups.com
Here is a simple Sample of Ajax upload using the HTML5 File API

frontend javascript
=================
$("fileupload").observe("change",handleupload);

function handleupload( e )
{
var el = e.findElement();
new Ajax.Request("backend.php?uploadfile=1",{"method":"post","postBody":el.files[0],"onSuccess":returnupload});
}

backend.php
=====================
if(isset($_GET['uploadfile']))
{
$uploaded_file = file_get_contents("php://input");
file_put_contents("/tmp/myfilename",$uploaded_file);

=====================

You can also add other events to the Ajax call to see upload progress as well, but again will not work with IE - works in Firefox/Chrome/Safari though


Jason Westbrook | T: 313-799-3770 | jwest...@gmail.com
Reply all
Reply to author
Forward
0 new messages