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.
Asked
Active
Viewed 2.3k times
14

tftd
- 16,203
- 11
- 62
- 106

user306205
- 141
- 1
- 1
- 4
-
3I wonder what "file inclusion tag" is? I'm guessing it doesn't work, but interesting term/idea. – Darryl Hein Apr 20 '11 at 08:29
-
7I think he wanted to say with words :)) – Bakhtiyor Jun 22 '11 at 11:25
-
check http://stackoverflow.com/questions/2320069/jquery-ajax-file-upload – Imdad May 22 '12 at 18:26
-
You can use only javascript to do it, here's [complete code](http://stackoverflow.com/a/27602218/2835520) – IgniteCoders Dec 22 '14 at 11:56
5 Answers
8
- 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

Manki
- 3,779
- 4
- 25
- 18
2
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

Nikita Rybak
- 67,365
- 22
- 157
- 181
1
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/

zamoldar
- 548
- 10
- 13
0
Here some I found http://blog.insicdesigns.com/2010/02/10-best-ajax-file-uploader-for-your-web-application/ and also jquery upload plugins

kaostricks
- 1
- 2