Ajax Interactive File Upload With PHP
How do I start with creating a file upload mechanism that works via Ajax? I've written file upload scripts before but they involved no JavaScript, just submitting a form with a modified encoding type attribute. I need the file upload to have the following features:
- Progress bar
- Error checking (for network connection drops, bad data, etc)
- Absolutely no "manual" form submission, Ajax takes care of it all.
And finally you know those upload buttons that allow you to select multiple files at once compared to the that only lets you select one file at a time? How can I implement those as well?
I'm u开发者_Python百科sing PHP as my backend btw.
You can find answers for your questions by looking at already done ajax file uploaders. There are many different plugins for jquery for example. One of the good place to start is to look at elfinder. Its based on jQuery & jQuery UI frontend and has Python and Php connectors for backend. Here are another usefull links:
- jQuery.upload - A simple ajax file upload plugin
- Multiple File Upload widget with Drag&Drop support for jQuery
- jQuery File Upload Demo
- elFinder - file manager for web
The main thing, that you should understand, that its not possible to upload files using xhr-requests. And for today, the only way to upload files, is to use hidden iframes, and some javascript magic to carry out the work.
I've been searching for good file upload scrips for a long time. I've been using the YUI file uploader most recently, but the following should work well with PHP. For some reason I had a heck of a time learning how to get the YUI to work, plus it uses Flash to do the actual upload.
http://aquantum-demo.appspot.com/file-upload
with set up information for PHP on this page:
https://github.com/blueimp/jQuery-File-Upload/wiki/Setup
精彩评论