I'm sure this has been asked before, but as I can't seem to find a good answer, here I am, asking... again. :)
Is there any way, using only a mixture of HTML, JavaScript/AJAX, and PHP, to report the actual progress of a file upload?
In reply to anyone suggesting SWFUpload or similar:
I know all about it. Been down that road. I'm looking for a 100% pure solution (and yes, I know I probably won't get it).
Monitoring your file uploads with PHP/Javascript requires the PECL extension:
uploadprogress
A good example of the code needed to display the progress to your users is:
Uber Uploader
If I'm not mistaken it uses JQuery to communicate with PHP.
You could also write it yourself, It's not that complex.
Add a hidden element as the first element of upload form, named UPLOAD_IDENTIFIER
.
Poll a PHP script that calls uploadprogress_get_info( UPLOAD_IDENTIFIER )
It return an array containing the following:
time_start - The time that the upload began (unix timestamp), time_last - The time that the progress info was last updated, speed_average - Average speed in bytes per second, speed_last - Last measured speed in bytes per second, bytes_uploaded - Number of bytes uploaded so far, bytes_total - The value of the Content-Length header sent by the browser, files_uploaded - Number of files uploaded so far, est_sec - Estimated number of seconds remaining.
Let PHP return the info to Javascript and you should have plenty of information. Depending on the audience, you will likely not use all the info available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With