Showing file upload progress with PHP and Drupal

Submitted by tomo on January 31, 2011 - 7:01pm

First, see if you have either or both APC's rfc1867 and PECL's uploadprogress. Check phpinfo() output to see what extensions are installed and check pecl-APC/apc.php to see if it's enabled and if rfc1867 is on. You only need one and you may need to disable one if you have both. Uploadprogress is enabled with the line "extension=uploadprogress.so" in your php.ini (assuming Apache on Linux/BSD) and APC rfc1867 upload progress is enabled with "apc.rfc1867 = 1". PECL uploadprogress is better for multiple concurrent uploads so go with that and uncomment the "apc.rfc1867 = 1" line, but if you can't get PECL uploadprogress to work then disable it, make sure "apc.enabled=1" and set apc.max_file_size and upload_max_filesize is sufficiently high so that uploads take more than a few seconds.

Next, test outside of Drupal. For uploadprogress, download the three php files at http://svn.php.net/viewvc/pecl/uploadprogress/trunk/examples/ and put them in your web directory. Uploadprogress works by looking for a hidden POSTed field called UPLOAD_IDENTIFIER with an id that will be used for requesting upload progress via ajax.

For APC rfc1867 use the code at http://www.ibm.com/developerworks/library/os-php-v525/index.html or the single file at http://progphp.com/progress.phps. It works similar to uploadprogress with a APC_UPLOAD_PROGRESS (set with apc.rfc1867_name) field to set the id for the upload.

If these examples fail, the cause may be another module/extension. If you're running any of these, try disabling them and re-running the tests:
FastCGI
mod_security
PHP patched with suhosin

OpenBSD's PHP is by default patched with the suhosin hardening patches. Suhosin earlier than 0.9.26 won't work with uploadprogress so you'd need to re-build PHP with a newer suhosin or without suhosin. In OpenBSD 4.4's port tree, building php5 with FLAVOR=no_suhosin has some issues. You can just comment out the .if ${FLAVOR:L:Mno_suhosin} section in ports/www/php5/Makefile and the post-patch target in ports/www/php5/core/Makefile to really make sure the suhosin patches aren't applied. You can also remove --enable-fastcgi from the configure options to disable FastCGI.

For more common solutions to uploadprogress you can go straight to the source: http://blog.liip.ch/archive/2009/03/31/upload-progress-meter-common-issues-and-some-answers.html

Read the rest of this article...
tomo

Another option which doesn't require server support but requires Flash is SWFUpload http://code.google.com/p/swfupload/ but it's Drupal module (http://drupal.org/project/swfupload) "is currently in Beta and has a security flaw that needs to be sorted out. Beta releases should never be used on production sites."

FancyUpoad requires MooTools (which won't play well with jQuery, which Drupal uses) and doesn't have a Drupal module.

© 2010-2014 Saigonist.