BrunoLM
BrunoLM

Reputation: 100381

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 size.

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):

Upvotes: 0

Views: 897

Answers (2)

Voropie
Voropie

Reputation: 245

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/.

Upvotes: 2

Pekka
Pekka

Reputation: 449783

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.

Upvotes: 1

Related Questions