Oracle Magazine Special offer for AjaxImpact.com Visitors!! Subscribe to Oracle Magazine for Free!
AJAX IMPACT


TUTORIALS
Asynchronous file upload with AJAX progress bar in PHP
03/12/2006 By Thomas Larsson


I wanted to use an asynchronous file upload, like the one on gmail. This means that the file is uploaded in the background, allowing you to still use the page while the file is being uploaded. Since the XMLHttpRequest object doesn’t support file uploads, this had to be done using iframes. Whenever the file input changes, the file is uploaded to the cgi-script in a hidden iframe. The cgi-script writes the total size of the upload and the actual uploaded file to temporary files.



When the upload starts, a Prototype Ajax.PeriodicalUpdater object is created. This object calls a PHP file twice every second using AJAX. The PHP file checks the temporary files while they are being written by the perl file, and returns the total progress in percentage of total upload size. The percentage value is used to set the width of the progress bar.

You can download the complete source code here

   Read More...

 Rate this Ajax Tutorials
Error connecting to mysql