PHP 5.2 upload progress meter

Yesterday I’ve spent considerable amount of time in order to find out more about the most interesting new PHP 5.2 feature – hook for upload progress meter. Except for this link I haven’t found anything else, no php source code example how to make one.

However, after I looked at internal php mailing list archive, I’ve found this thread, still no php data found, but Rasmus mentioned link with an example at http://progphp.com/progress.php. I immediately tried upload and it looked very cool. Then I looked at html source code and noticed one unusual thing there: APC_UPLOAD_PROGRESS hidden field inside of html source. I knew it must be important so I’ve googled for it, and insteresting enough first result was source code of Rasmus example above :)

So, I took complete source (I figured out later it is upload meter example made by Rasmus Lerdorf) and quickly tried to make it working under my fresh new installed PHP 5.2.0. Unfortunately, it didn’t work since it needed apc stuff installed. After I looked at apc documentation, I found that I need to grab it from list of pecl dll’s for windows php 5.2 version. Unfortunately, after I’ve downloaded it from here I’ve noticed apc dll is missing there ?!!

Again, I had to google for php_apc.dll and after a while found needed dll available at http://pecl4win.php.net/ext.php/php_apc.dll. In order to make it working, you have to save dll file under php/ext dir (i.e. c:\php\ext on windows) and put this to php.ini:

extension=php_apc.dll

Unfortunately, it still didn’t work, so I’ve looked at apc docs further. Finally on this page I’ve found apc have new “special feature” which is directly related to our new upload feature.

    apc.rfc1867             RFC1867 File Upload Progress hook handler is only available
                            if you compiled APC against PHP 5.2.0 or later.  When enabled
                            any file uploads which includes a field called
                            APC_UPLOAD_PROGRESS before the file field in an upload form
                            will cause APC to automatically create an upload_
                            user cache entry where  is the value of the
                            APC_UPLOAD_PROGRESS form entry.
                            (Default: 0)

After I figured out on my phpinfo page apc.rfc1867 setting is turned off, I’ve added

apc.rfc1867 = on 

in php.ini, and after restart was finally able to enjoy new fancy upload progress meter :)

upload progress meter

Btw, upload also depend of json turned on as well, but it was already turned on so I didn’t have any more problems.

About the code Rasmus used in his example, I am tired to analyze it more now, but obviously it use Yahoo! User Interface Library to create progress bar and json/apc to control it from php during file upload.

I hope this will be helpful for someone. Enjoy ;)

Comments

  1. Tom
    March 25th, 2009 | 11:44 am

    Hi Yogesh,

    have you set
    apc.enabled = 1
    in your php.ini? All settings are explained at
    http://de.php.net/manual/en/apc.configuration.php

    Also, in the APC package available at
    http://pecl.php.net/package/APC
    you can find a script called “apc.php”. Call it in your browser and you can monitor the status of your APC cache.

    Cheers
    Tom

  2. March 25th, 2009 | 12:15 pm

    @Yogesh
    It looks that you don’t have apc installed.

    Old link in my article doesn’t work anymore but you can downlod it from link Tom provided.

  3. July 9th, 2009 | 10:25 am

    Doesn’t work, tried uploading a 500 MB file and it said completed within 3 seconds. I know my upstream isn’t more than 48KB/s, so there is no way it actually uploaded.

    I am also not going to digg this, because its really no brainer, Upload with progress bar has been around for quite some time, which all they did was refresh the popup window. Now it just a AJAX version of the same.

    Firefox 1.5.0.1.

  4. August 26th, 2009 | 3:04 am

    […] Caught in a Web » PHP 5.2 upload progress meter http://www.dinke.net/blog/2006/11/04/php-52-upload-progress-meter/en – view page – cached Yesterday I’ve spent considerable amount of time in order to find out more about the most interesting new PHP 5.2 feature – hook for upload progress meter. Except for this link I haven’t found anything else, no php source code example how to make one. — From the page […]

  5. alex
    September 9th, 2009 | 12:58 am

    I have been trying to get this to work, and have exactly the same issue as a few people on here. It works great in IE, but not Firefox3…

    I get the progress meter comeup and then it shows me {blah:1 blah:1} – but the file is uploading. It just doesn’t seem to refresh the parent as it doe sin IE.

    Any ideas would be appreciated..

Leave a reply