Drupal & PECL uploadprogress

FileField and ImageField 3.0 have just been released and bring with them the ability to display an upload progress meter in the FileField widget while a file is being uploaded. As ImageField uses the FileField widget this works for ImageFields too.

The original article FileField and ImageField 3.0 for Drupal 6 Released points out:

Probably the most exciting improvement is the addition of upload progress indication. This enhancement requires the PECL uploadprogress PHP extension, but adds a real asset to sites that use FileField for podcasts, videos, or other large files.

It took me a while to figure out how to install this extension so I thought I'd do a quick post about it. These instructions are probably valid for other PECL extensions but since this is the only one I have installed I wouldn't like to say for sure.

Installation on Unix/Mac

Please note: These instructions are only valid if you have problems running pecl install uploadprogress
  1. Download the PECL uploadprogress extension

  2. Extract the uploadprogress-1.x.x.tgz archive, cd into the extracted folder and run these commands in Terminal:

    phpize            # prepares the PHP extension for compiling
    sudo make install
  3. Check that the directory for the extensions is correct. The last line of the output returned from the make install command (on my system) is:

    Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20060613/

Open php.ini and edit the extension_dir directive, replacing it with this path.

  1. Add the extension to php.ini by adding this line extension=uploadprogress.so
  2. Restart apache

You should now have the PECL uploadprogress extension installed.

Installation on Windows

It's very simple to install on Windows:

  1. Copy the uploadprogress.dll file from pecl4win into the path set for extension_dir in php.ini.
  2. Add the following to php.ini:
  1. Restart apache.

The pecl4win site was down for maintenance at time of writing so you could try here in the meantime (thanks to chriscohen for the link).

If you're using using WampServer 2 then it already comes with php_uploadprogress.dll installed (thanks again to chriscohen for pointing this out and testing that both methods work).

Increasing Maximum Filesize

To increase the maximum filesize you need to set 2 directives:

Generally you should set post_max_size to double what you set upload_max_filesize to. This means you can upload 2 files of your maximum limit for each POST and seems like a good middle ground.

The memory_limit directive should also be set above the value of post_max_size so your server can handle the uploads.

There are 2 ways you can set this directive:


Edit php.ini and modify these directives:

upload_max_filesize = 128M
post_max_size = 256M


Edit .htaccess and add:

php_value upload_max_filesize 128M
php_value post_max_size 256M

Adjust 128M and 256M with the sizes you require.

Increasing PHP's Memory Limit

You could edit the memory_limit directive in php.ini but I personally like to set that directive on a site-by-site basis. This helps to keep sites that don't need such a large memory_limit nice and efficient.

Instead you can set the directive in settings.php by adding this line just below the other ini_set lines:

ini_set('memory_limit', '256M');