Ajax based File-Upload for PHP 5.2 under Win32 system#
Top Announcement: 10-march-2009 EmForge-0.30 with ActiveDirectory and OpenID support released! See News
for details.
If you will look into Google for words 'file-upload, ajax, php' you will find a lot of links to the different articles described how to do it. But there were several problems:
We had a task to implement uploading of several files with PHP and displaying progress-bar on windows... As result - attached file
contains solution for this task. I will just describe major ideas:
- Ajax-based upload itself implemented with using iframe (standard solution for this task);
- demo.html contains all client code - it is also used prototype java-script framework
- big friend for web-developers;
- receiving the file is implemented in uploader.php;
- For getting upload-progress information we are using Ajax.PeriodicalUpdater Prototype function on client-side and monitor.php - on server-side. Monitor.php simple get information from uploadprogress extension;
- To make uploadprogress extension working under windows we had to fix it a little bit. Source code and result dll included in separate attachments here
. I hope this fixes will be included by extension developer and correct version will be included into php destribution by default:
- Removed PHP_EXPORTS define in project settings;
- Use fopen instead of (todo). We are not very familiar with PHP extensions development, but in our case this function caused exceptino then we tried to use opened file with fprintf and fget;
- Delete target file before renaming;
- Cast time_t to the integers;
- It is important to set No-Cache options in monitor.php - we got this code working under FireFox but it defently did not work under IE (both 6.0 and 7.0) until we did not included this option.