It is quite easy to implement upload progress feedback. It will work if the PHP installation either has APC enabled (which is very common these days), or has the small PECL extension named uploadprogress. If none of those two are available, we simply use our current upload indicator.

To test this on APC, please make sure to set apc.rfc1867 = 1 in your PHP configuration.

CommentFileSizeAuthor
upload-progress.patch3.18 KBDamien Tournoud
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Wow. Fascinating! This is fantastic, I looked into this exact problem when converting upload.module to to #ahah, but I didn't know there was any way to do this in PHP. Is there anyway we could automatically set the APC variable through .htaccess? It doesn't seem to be an entirely common option.

quicksketch’s picture

To quote Steven:

If PHP supports ad-hoc upload info in the future like Ruby on Rails, we can implement that in 5 minutes.

And so we can. :)

rickvug’s picture

This would be a excellent usability enhancement and a killer end-user feature. Tags added.

yoroy’s picture

Where will we see this in core? in update.php and when uploading attachments?
@rickvug: really killer? I wouldn't dare to brag about this. ("Drupal 7, now with progress bars for your upload!!!")
Let's keep the bar high for items on the list of killer features :-)

Still, would be a nice touch indeed. Can we get a screenshot please?

Damien Tournoud’s picture

Issue tags: -Needs screenshots

I'll update the patch later this day.

Edit: removing the screenshot.

drewish’s picture

subscribing... this is really cool but i wonder if there's a bug that might make this less useful. as per http://docs.php.net/manual/en/apc.configuration.php#ini.apc.rfc1867

Note that the file upload tracking is not threadsafe at this point, so new uploads that happen while a previous one is still going will disable the tracking for the previous.

quicksketch’s picture

Status: Needs review » Needs work

I've been trying to backport this to FileField and I've found one obvious flaw: the current approach limits us to one progress-enabled upload field per page. Since "APC_UPLOAD_PROGRESS" is a required item in the POST array, printing it in the HTML makes it so that there can only be one progress ID per form. Drewish points out APC upload progress isn't thread-safe, so maybe this is a moot point, but I feel it would be better to not hard-code the APC_UPLOAD_PROGRESS element into the page, and instead dynamically add it to the page just before submitting the form (then remove it afterwards) so in the case there are multiple progress-enabled fields, the value appears in the POST array based on the button that was pressed.

quicksketch’s picture

I now have a working version of this for Drupal 6 in FileField, see #318960: Upload Progress Bar (rfc1867 support).

Some more observations:

  • The PECL uploadprogress library is much, much more reliable in handling multiple uploads, we should make it the default if available.
  • The APC special input name (APC_UPLOAD_PROGRESS) and other settings might be changed by the server configuration, we should check these rather than assuming defaults, see http://us2.php.net/manual/en/apc.configuration.php
  • A hook_requirements about this feature and its current status might be helpful.
bennos’s picture

I have mentioned the same thing here:
http://drupal.org/node/318960

pecl upload progress is only supported by the apache. The lighttpd 1.4 has no support. the comming release of lighttpd 1.5 wil have support.

I do not know the support of other webserver, but I think the pecl extension upload progress is not the best way at this point.
Other webserver are locked out. Developers must touch the core to implement support of special webserver upload modules.

Why not implement a full ajax upload solution?

like this http://plugins.jquery.com/node/6728 or any other jquery solutions to get a better uploading.

quicksketch’s picture

This solution is an AJAX solution. The library you linked to just lets you upload via AJAX (which Drupal already does), it doesn't provide upload progress. Upload progress needs server-side support, since normally PHP doesn't even start executing the response script until after the entire file is already uploaded. However, it's definitely clear that this will need some more work, it's good that FileField has added this support so we can find all the various bugs. So far we already have:

#437254: Upload progress does not work in Lighttpd & nginx
#435828: Progress bar shows progress only for last file when set to unlimited (with exceptions)
#435678: Progress bar not HTTPS compatible

davidcgutman’s picture

Would you guys mind including some more detailed instructions on how to enable this feature? I'm a bit of a PHP novice, so what is obvious to you guys probably isn't obvious to me (or many other Drupal users). Since this notification shows up in the Status Report, adding a little more documentation would be very welcome. Looks like a great result though...

quicksketch’s picture

davidcgutman, this issue is for Drupal core. You're talking about the progress bar in FileField. See #441046: Upload Progress Bar Documentation.

Aren Cambre’s picture

Marked #22234: progress indicator as duplicate of this one.

rickvug’s picture

Status: Needs work » Fixed

@quicksketch Looking at core's file.module, it looks to me like this patch was included so I'm marking as fixed. Please re-open if there are still issues to be addressed. Excited to have this in core!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

gpk’s picture

Yes looks like this was part of the original implementation of file.module. And is now documented on the API site: http://api.drupal.org/api/function/file_progress_implementation/7.

Note that AFAIK both uploadprogress and APC work only in mod_php environments, i.e. not under CGI/FastCGI.