File Uploadin by Ajax

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
mr00047
Forum Newbie
Posts: 14
Joined: Fri May 12, 2006 1:01 pm

File Uploadin by Ajax

Post by mr00047 »

Hello

I want to know is there any way to upload a file using Ajax without submiting the page(also without using IFrame).

If you have a solution please provide a sample code.

Thanks.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

I have a working example that works, however it uses the iframe method... There is no other way that I have found that will let you do a file upload, without using a reload, or an iframe... When I get home tonight, I can post a sample...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I do not believe that the actual upload can be done via xmlhttprequest. But the wrapper can be Ajax.
(#10850)
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

The way I have it working is very degradable... On page load, it removes the submit button and the file upload field, appends the iframe which has a document that replicates the file upload field and the submit button (future versions will use the dom to clone the existing fields), on the iframe page load, it replicates all the existing fields into the current (iframe) page, on submit, it will do the upload and reload the iframe, which causes the page to output more onload javascript which will call a function in the parent frame (the actual page).

It works very seamlessly, with or without javascript...
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Right. If JavaScript was allowed to upload files willy nilly, you'd be presented with a security threat.
Post Reply