Upload progress using javascript only
Is it possible to make a upload progress using javascript only? (maybe with some ajax to a server-side code)
Having a form such as
<form method="post" action="upload.html" enctype="multipart/form-data">
<p>Select file to upload: <input type="file" name="selected_file"></p>
<p><input type="submit" value="Upload the file"></p>
<div id="progress"></div>
</form>
I want to display things as upload progress, speed, total si开发者_开发百科ze.
I don't want tools for it, I want to understand how it is done without flash, and from scratch.
Similar questions (none from scratch):
- Uploading a file
- How to implement file upload progress bar on web?
- Upload progress using pure PHP/AJAX?
HTML5 is your friend. In particular, you should read up on File API specifications of HTML5 (w3.org/TR/FileAPI/). In brief, it's done with the help of FileReader interface. Googling might suggest a read such as this one at matlus.com/2010/09/html5-file-upload-with-progress/. Also, there are some limits of the API atm and you might want to learn about those from hacks.mozilla.org/2010/06/html5-adoption-stories-box-net-and-html5-drag-and-drop/.
I see now what you mean by "from scratch". I know of no way to do this that doesn't require some server-side fiddling.
If you have access to PHP 5.2 and can install additional modules, I think this is the closest you'll get regarding a step-by-step process:
What's new in PHP V5.2, Part 5: Tracking file upload progress
It requires APC but as I said, there is no "pure" PHP / Ajax solution as far as I know.
This question contains a number of additional interesting resources.
精彩评论