0

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

Community
  • 1
  • 1
BrunoLM
  • 97,872
  • 84
  • 296
  • 452
  • possible duplicate of [Upload progress using pure PHP/AJAX?](http://stackoverflow.com/questions/653063/upload-progress-using-pure-php-ajax) – Pekka Jul 14 '10 at 11:46
  • Just a brief idea on how it is done and where I could search for resources would be enough. I am just curious about it. – BrunoLM Jul 14 '10 at 11:53

2 Answers2

2

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

Voropie
  • 245
  • 1
  • 2
  • 7
1

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.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088