user306205
user306205

Reputation: 141

Ajax file upload

I want to upload a file using Ajax and php. I have a form with <input type="file"> tag. I want when user browses a file and clicks on submit, the file to be uploaded without a refresh. How should I do this ? It does't matter if refresh occur but i want to upload file with help of ajax.

Upvotes: 14

Views: 23287

Answers (5)

zamoldar
zamoldar

Reputation: 598

This plugin uses XHR for uploading multiple files with progress-bar in FF3.6+, Safari4+, Chrome and falls back to hidden iframe based upload in other browsers, providing good user experience everywhere. check this: http://valums.com/ajax-upload/

Upvotes: 1

Manki
Manki

Reputation: 3909

  • Use a hidden iframe and set your form's target to that iframe's name. This way, when the form is submitted, only the iframe will be refreshed.
  • Have an event handler registered for the iframe's load event to parse the response.

More details on my blog post: http://blog.manki.in/2011/08/ajax-fie-upload.html

Upvotes: 8

Nikita Rybak
Nikita Rybak

Reputation: 67986

I did it with this jquery plugin. It pretty much mimics standard jquery ajax functionality, but also allows you to send data using iframe. No flash involved, pure javascript.

http://malsup.com/jquery/form/

Here is a file upload example
http://malsup.com/jquery/form/#file-upload

Upvotes: 2

Mitch Dempsey
Mitch Dempsey

Reputation: 39869

Take a look at SWFUpload, it should do what you want.

Upvotes: 0

Related Questions