View Full Version : ajax form submission, but with a file input

12-10-2008, 09:30 PM
Hey all, I have some code that I'm using to handle my data submission as an ajax form asynchronously, and all my data is passing fine, except I don't know how to make it work for a file, I don't have any code for it and I've been looking at google and haven't found anything, can someone help me find out what I need to add to handle my file input?


// Loop through form fields
for (i=0; i < thisform.length; i++)
//Build Send String
if(thisform.elements[i].type == "text"){ //Handle Textbox's
formdata = formdata + thisform.elements[i].name + "=" + escape(thisform.elements[i].value) + "&";
}else if(thisform.elements[i].type == "textarea"){ //Handle textareas
formdata = formdata + thisform.elements[i].name + "=" + escape(thisform.elements[i].value) + "&";
}else if(thisform.elements[i].type == "checkbox"){ //Handle checkbox's
formdata = formdata + thisform.elements[i].name + "=" + thisform.elements[i].checked + "&";
}else if(thisform.elements[i].type == "radio"){ //Handle Radio buttons
formdata = formdata + thisform.elements[i].name + "=" + thisform.elements[i].value + "&";
//finally, this should theoretically this is a select box.
formdata = formdata + thisform.elements[i].name + "=" + escape(thisform.elements[i].value) + "&";

Obviously Ive totally left out the file part.
How does it get handled into the php $_FILES file array?

12-10-2008, 11:36 PM
Or perhaps is it possible is a better question?

12-11-2008, 01:56 AM
Apparently, the only way (I could think of) that is possible is to use the iframe technique.

You target the upload, to that of the iframe, and when the iframe has loaded, instruct the parent page to do somethings you want.

You might find these links useful:

12-16-2008, 10:46 PM
I have tried that stuff too, to no avail, best thing is to use ur hidden iframe method, display a waiting gif....and if ur server can use perl, u can find some free perl scripts that will even show u the progress bar 'cos perl (not php) can access the posted raw data and determine the size of the file before upload, and can upload in chunks.....