A PHP File uploader with progress bar.
It took me five years to figure out something that PHP cannot do. For a recent project we needed to display a progress monitor as files were being uploaded to the server. We quickly realized that PHP cannot produce such an indicator dialog.
To create a progress bar you need to measure how many bytes have been uploaded and compare this against the total number of bytes to be uploaded. (The total file size) This information can only be retrieved by manually processing the form submission.
While other technologies like perl or J2EE gives access to the raw POST data PHP does not. Strangely enough PHP does have a variable named RAW_POST_DATA but this is populated only if the engine cannot identify the content type of the POST data. This might tempt you to change the enctype of the form field to something other than multipart/form-data. You would quickly realize that just the filename is passed on to the server instead of the file being uploaded.
All this is rather suprising if you have become used to the access provided by php to lots of low level functionality. On the other hand when we did lekana.com we implemented a progress bar in JSP and found it really easy going.
The answer that we came up with mixes PHP with perl. On most servers where PHP is installed you are certain to find perl as well. Though the perl manual strongly urges you to avoid tinkering with the raw post data, it's quite easy to manipulate it to create a pop that indicates upload percentage.
Then again most PHP programmers today aren't comfortable working with perl. So we will pass on the processing to a PHP script once file upload is complete. You are then back in familiar territory.
The downloadable tarball contains a perl script to produce a progress indicator, a simple HTML form and a php script to take over once upload is complete. Please note that not much attention has been paid to file locking issues.
If you have trouble installing, please take a look at the online docs, and support forums for the project at sourceforge.net
Please also see The JSP Edition