About Us

News

RSS
A Useful PHP File Upload Progress Meter

UPDATE - Click here for a new (better) PHP Upload Progress Bar Script


If you're like me, you want a PHP upload progress meter that is actually useful in your web applications. All of the upload progress meters that I've run across only include the file upload field by itself, which is not realistic in an actual web application situation. You will most likely be entering other information along with uploading a file. The demo is an adaptation this php file upload progress meter.

The demo below will show you how to display a progress upload meter while also entering other information within the same form.

The progress meter will only show if you actually choose a file to upload. If you are just entering information in the text fields, then the progress meter will not show.


Single File Upload


Multiple File Uploads


YUI Code Library

You need this to display the progress meter bar. Look at demo source code for essential JS files.


Requirements:
You must have APC (Alternative PHP Cache) and PHP 5.2 installed on your server for any of this to work.

This is really the only potential problem for those who don't have root access to their server. It's not that difficult to install, but you either have to have root access, or your hosting provider will need to do this for you. The script will definitely not work without this.

Installing APC on your Linux server
Installing APC on your Windows server
Important: Make sure to include apc.rfc1867 = on in your php.ini file after APC is installed. Your php.ini file should be located in the /etc/ directory.


Resources
Upload Progress Meter by Rasmus Lerdorf
This is where the majority of my script came from. In my opinion, this is the best and cleanest php upload progress meter on the web.



Go Back...

sandeep wrote on 12/18/08 at 11:08pm...
"hi thanks for the code. I have used this code but could not upload a file.I have installed APC and i m using php version 5.2.3, apache version 2.2.4 . I have also included apc.rfc1867 = on in my php.ini file.When i upload a file it does not show any error and shows that file has been uploaded successfully,But does NOT upload file in the destination folder.

PLEASE HELP .IT`S VERY URGENT......"
John wrote on 12/18/08 at 11:12pm...
"Check the following:

1. Use phpinfo() to see if APC is really installed.
2. Make sure your folder has full write permissions (777). If you're uploading to the folder where you files reside, then that folder must also be set to 777.

"
Sandeep wrote on 12/19/08 at 12:13am...
"HI john
Thanks for your quick response.
All things were in place. The problem was related to the caching of my browser.
Now it is working fine.
But now when i am uploading a file , all time during uploading progress bar does not move. But after some time file uploads successfully.

Any idea Please........"
John wrote on 12/19/08 at 12:39am...
"Does it work correctly if you use the exact code that I've used? "
Sandeep wrote on 12/19/08 at 3:55am...
"Yeah it does, Apart from visualization of "progress" of progress bar "
sandeep wrote on 12/21/08 at 10:55pm...
"i am already using apc.rfc1867 = on in my php.ini.
i am using yui 2.6.0. Does that make any difference?? "
sourabh wrote on 12/23/08 at 2:48am...
"@sandeep

check for "progress.php" file reference in john's code. change this filename according to your filename. i copied his code and saved it as "index.php" obviously, it didn't worked, then i renamed the file to "progress.php" and it worked. i also used the same YUI files as john's. Hope it helps

@John
Gr88888 work man, i m definitely gonna use it in my office projects :)"
John wrote on 12/23/08 at 9:08am...
"I believe Sandeep's issue was that he was testing it locally, so the file uploaded instantly, thus not showing any incremental progress on the progress bar. Also, you can rename the progress.php file and do a find/replace to replace 'progress.php' with the name of your file."
phani krishna wrote on 1/10/09 at 12:56am...
"Hi Jhon,

I saw the demo of your script it's looking good. Here i have one doubt. I already having my own uploading script. From there i am able to upload files into my server properly. I want to integrate the progress bar of your script into my script. I cant install your whole scrit for file uploading because i have many options in the backend in my existing script, so i want only the progress bar module of your script. Can i extract that part and use in my script? If yes please guide me.

Thanks
Phani Krishna"
John wrote on 1/10/09 at 10:30am...
"Phani - I would need to see your current code to determine how you should integrate the progress bar. Feel free to email it."
Andy wrote on 1/15/09 at 3:19am...
"Hi John, this is a neat script! Thank you.
I have a working php script to handle my uploaded files. Now I would like to use your / Rasmus' script to do the upload. But I don't know where I would refer to my script or do move_uploaded_file(). Could you give me a hint? Thanks, Andy"
Andy wrote on 1/15/09 at 11:22am...
"...I got it..."
mark wrote on 2/09/09 at 7:26am...
"hi john,
is there a way to get an error-message if the text-field is empty - before starting the upload script? can you help me?"
Slavi wrote on 2/16/09 at 11:45pm...
"Is there a way to check the size with APC and then stop the upload if the file is bigger than 10 MB ?"
Valentin wrote on 3/06/09 at 6:26am...
"Hi,
i want to use these beautifull script.
when i am uploading a file , all time during uploading progress bar does not move. But after some time file uploads successfully.
i've try this with your code but there is the same problem.

here my apc configuration, is a mistake?
apc
APC Support enabled
Version 3.1.0-dev
MMAP Support Disabled
Locking type File Locks
Revision $Revision: 3.151 $
Build Date Nov 8 2007 23:20:54

Directive Value
apc.cache_by_default On
apc.enable_cli Off
apc.enabled On
apc.file_update_protection 2
apc.filters no value
apc.gc_ttl 3600
apc.include_once_override Off
apc.localcache Off
apc.localcache.size 512
apc.max_file_size 50M
apc.num_files_hint 1000
apc.report_autofilter Off
apc.rfc1867 Off
apc.rfc1867_freq 0
apc.rfc1867_name APC_UPLOAD_PROGRESS
apc.rfc1867_prefix upload_
apc.shm_segments 1
apc.shm_size 64
apc.slam_defense 0
apc.stat On
apc.stat_ctime Off
apc.ttl 0
apc.user_entries_hint 4096
apc.user_ttl 0
apc.write_lock On

any idea?

i'm sorry about my bad english, i'm from germany.

thanks."
David wrote on 3/12/09 at 2:04am...
"Am I misreading the manual where it says:
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.

Does this mean that this will cause problems with two concurrent file uploads? eg. progress bar for one person fails if another person starts uploading?
"
josy wrote on 3/24/09 at 5:03am...
"please help
where is these files?








and progress.php "
josh wrote on 3/26/09 at 9:55am...
"Hi John, you're post is fairly recent and I'm hoping you can help me with my APC woes. I have a site where I'm attempting to run your code. The site is multiplesmarket.com/UploadDemo.php. The problem I'm having, and that I have with my own tests, is that apc_fetch just doesn't work.

I've copied the php file, the specified YUI files, and I have APC enabled (multiplesmarket.com/info.php). Can you take a look? By default, my host runs Apache 1.3. I'm wondering if that could be it."
John wrote on 3/26/09 at 10:47am...
"Josh - I'm not positive what could be causing the problem you're running into, but my guess (like yours) is that it's either that you're not running Apache 2 - or your server is running Apache in CGI mode (Server API CGI/FastCGI)."
Subeesh wrote on 4/03/09 at 7:53am...
"Hi,
I have tried this out, but the problem is, after pressing the submit button, on a fraction of a second the progres bar seems displayed, but after that, it displays some text like

{"total":9372,"current":9372,"rate":74976,"filename":"exchg_myoffers_main.tpl.html","name":"file","temp_filename":"\/tmp\/php1663g0","cancel_upload":0,"done":1}

What may be the problem? I saw in the code, style.css is included.. Fomr where does I get this style ?

Thanks in advance
Subeesh"
Manolo wrote on 4/16/09 at 7:27am...
"Hi Johnboy,

I have your demo running quite well in my local server but I would like to integrate it in a complex form that I am developing.

This form has a lot of hidden input fields and several buttond to download files and go back to other form which uses the hidden input field in this one.

Is there any way to run you progress bar iframed to avoid data lossess? You use GET to pass the key, so I loss all the form data!

Thanks in advance

"
Emerson wrote on 4/19/09 at 3:23pm...
"Hi Valentin

Important: Make sure to include apc.rfc1867 = on in your php.ini file after APC is installed.

look bellow

...
apc.report_autofilter Off
apc.rfc1867 Off ----> here
apc.rfc1867_freq 0
..."
Ingve wrote on 5/07/09 at 1:19pm...
"Loved the script.
Great work, dude.."
bill wrote on 5/15/09 at 9:35am...
"where are the uploaded files stored ?"
John wrote on 5/15/09 at 9:56am...
"In my example, they are stored in the same directory with the upload script. You can set the location yourself here:

$uploaddir = ""; //set this to where your files should be uploaded. Default is same directory as script.

Example:
$uploaddir = "files/"; //set this to where your files should be uploaded. Default is same directory as script. "
NIck wrote on 5/29/09 at 12:59pm...
"So anyway way to get this going if running Server in CGI Mode? apc_fetch() just returns false...
"
Alastair Battrick wrote on 6/12/09 at 7:56am...
"Brilliant, thankyou"
chaitra wrote on 7/03/09 at 6:03am...
"Dear Sir,

I am trying for image displying loading status bar using ur progress.php script and I have installed and configured php_apc in my php.ini file. Also I have enabled apc.rfc1867 = on in php.ini file. But when I executed this file it will show uploading file window but progress bar is not moving and file uploading is not done.

It is showing error like 'rate' is null or not an object.
Please reply me soon.
Thanks in advance

Regards,
Chaitra"
Karthik wrote on 8/13/09 at 12:27pm...
"The uploader seems to work but only shows 0% and 100%?
Try to upload a bigger file and it will say at 0% for a wile. Then it goes to 100%."
Karthik wrote on 8/13/09 at 12:29pm...
"How do i get the intermediate % values?"
Ertem wrote on 9/04/09 at 2:58am...
"Works without any problem.I tested locally,uploaded about 90-100mb without any problem.
But i want to show user the uploaded file s name,how can i do this?"
Ertem wrote on 9/04/09 at 8:06am...
"i solved previous question.

Now i want to post $uploaddir;$filename; variables to upload.php and show user the uploaded file name and directory using upload.php

I used action="upload.php" but variables on progress.php aren t sent to upload.php.

Any solution?
"
Alex wrote on 9/08/09 at 4:55pm...
"Is there any reason this would not work 'as is' in firefox 3? I have it working perfectly in IE, but I get exactly the same issue as Subeesh:
" I have tried this out, but the problem is, after pressing the submit button, on a fraction of a second the progres bar seems displayed, but after that, it displays some text like

{"total":9372,"current":9372,"rate":74976,"filename":"exchg_myoffers_main.tpl.html","name":"file","temp_filename":"\/tmp\/php1663g0","cancel_upload":0,"done":1}" Really like the simplicity of this but this one bit is killing me....

Appreciate some ideas.
Thanks

Alex.
"
EHCanadian wrote on 10/03/09 at 11:35am...
"Can you confirm this will work with the latest verion of yui 2.8.x as I wasn't able to out of the box"
Martin wrote on 10/19/09 at 11:14am...
"Hi John,

i am on shared hosting and have run phpinfo. What am i looking for to see if APC is installed?

as i have copied your script, the progress bar pops up but nothing animates and doesn't upload the file.

thanks"
STAR68 wrote on 10/25/09 at 6:04am...
"Thank you! It's excellent code!

But I have 3 question:
1. How to update current Rate upload?
2. How to Stop Uploading (a button to stop upload)
3. How to Seperate each file in each upload (not include all file in upload progress bar)"
Arun Kumar wrote on 12/14/09 at 12:47pm...
"the apc_fetch always returns false during the file upload but returns the array value only once the upload is get done. Any idea?
Runtime Settings
apc.cache_by_default 1
apc.coredump_unmap 0
apc.enable_cli 1
apc.enabled 1
apc.file_update_protection 0
apc.filters *
apc.gc_ttl 3600
apc.include_once_override 0
apc.max_file_size 1M
apc.mmap_file_mask
apc.num_files_hint 1000
apc.report_autofilter 0
apc.rfc1867 1
apc.rfc1867_freq 10k
apc.rfc1867_name APC_UPLOAD_PROGRESS
apc.rfc1867_prefix upload_
apc.shm_segments 1
apc.shm_size 30
apc.slam_defense 0
apc.stat 1
apc.stat_ctime 0
apc.ttl 7200
apc.user_entries_hint 4096
apc.user_ttl 7200
apc.write_lock 1"
Webmaster wrote on 2/10/10 at 7:19am...
"I integrated a new (better) PHP Upload Progress Bar Script in my PHP project.
But script shows %Nan instead of actual percentage. I have installed all server settings properly.

Please help me, how to fix this problem?

Thanks in advance.
"

 


Leave a comment

Your Email Address


Your Name


Message