tesUpload

One of the few things that PHP lacks that other web environments have, is the ability to report the progress of a file upload. This means that file uploads, especially uploads of larger files, can be extremely frustrating for end users when they don’t know if the upload is progressing or if it has stalled or if it has even started.
tesUpload solves this problem by using a perl script that handles the progress reporting. Don’t worry if you are a hardcore PHP programmer, you won’t have to touch the perl code at all. Just put the cgi-script in your cgi-bin folder and forget about it.
For a more in-depth explanation of how this works, see my original blog post on the subject.
Requirements
tesUpload requires a webserver running PHP and Perl CGI-scripts (it’s probably easier to find web hosts that do than ones that don’t).
Download
For support, bug reports & feature requests, please visit the tesUpload Sourceforge Page
tesUpload is published under the terms of the MPL. The source code is available in the Sourceforge CVS. tesUpload is based on megaupload by Raditha Dissanyake.

Ingenious - i wish i had thought of that.
Perl to upload the file instead of php, its much easier to get the file size.
I really wish you would implement a demo somewhere…
lkjahsdlkjf
Good example for showing the progress of file upload. Keep it up.
Yes, a demo would be nice.
Please, implement a demo!
I have downloaded and tried out tesUpload. Its great. A little simpler
to install than MegaUpload.
For improvements I would ask for:
1) A Cancel button. Many people who are uploading large files may need to
cancel the upload, but there is no obvious way to do this.
2) Multiple file uploads. MegaUpload has this by simply putting more Browse fields in.
If this were added it would also be nice to have the tesUpload show the progress
of each and a Cancel for each.
3) Once I browse and select a file, the upload begins before I hit the “Submit” button.
The upload continues writing into /tmp, but when that is done, the last step, writing
into the /tmp/uploads directory is not done until I hit Submit. It would be better
if the download did not start until I hit Submit.
I’ll see what I can do to add any improvements but I’m very new to PHP.
Thanks for making this available!
-Jim
Many thanks, this is awesome. Great work!
[…] AW: Upload mit Status Anzeige Hallo, das Thema hatten wir schon fters die Suchfunktion htte hier schnell weitergeholfen Unter anderem wurde dabei auch auf tesUpload hingewiesen. Gre, Matthias __________________ Gib einem Menschen einen Fisch, und er wird fr einen Tag satt. Lehre ihn Fischen, und er wird ein Leben lang satt. For every complex problem, there is an answer that is short, simple and wrong. Pessimism is safe, but optimism is a lot faster! Experiment: Kohlkopf (Erklrung) […]
Hello.
I tried to setup your script on my windows webserver. but whatever i do, the script always say that the temp-folder is not writeable. what can i do do run your script?
Thanks für your help!
Matthias
Hello!
Great script! It works amazing with all sorts of files, big and small!
One queston though: Is there any way to run the upload.cgi script through mod_perl?
get.cgi works fine, but upload.cgi seems to not pass the file name once it finishes the upload…
Many thanks!
Im confused I see a small sample photo that shows two files on this website. Is this code supposed to support multiple file uploads? I tried adding extra form elements with and so on in my index.php. Then I select some files. The files do indeed upload but I notice that some off the progress bars stop until the other uploads finished. Is this normal behaviour?
When you upload a file that exceed the maximum size the upload.js show many times the error message so a simple solution is to reload the page ( not nice but works ):
function updateFailure(pb,req) {
var mes = req.responseText;
pb.style.width=0;
alert(mes);
uploads_in_progress = uploads_in_progress - 1;
location.href = document.location;
}
It doesn’t work with Safari, does it?
[…] Página oficial: http://tomas.epineer.se/tesupload/ […]
Yeah, does it work with Safari? It is important to know.
Yes, it works with Safari. Took me about an hour to figure out all the quirks and configuration points, though.
suggestion: the twice-a-second updates are a bit much for my needs, and seem to gum up the process while on a slow connection. It’d be nice to have the updates as a variable in the .inc file.
Hello,
I keep getting these warnings:
Warning: PHP can’t write to temp dir ().
Warning: PHP can’t write to upload dir ().
What’s wrong?
Fixed the previous warnings, by adding the complete path.
But now it doesn’t show any progress and when I press submit it keeps alerting “File upload in progress…”
What should I do?
This is a nice example on how to avoid php annoyances,
if you cannot use rails.
A demo and a complete list of features will be also nice.
I cannot get this to work. The progress is not shown and the message that the “File upload in progress…” is continually shown while clicking the Submit button.
The files never seem to get written to either the temp directory or the permanent directory.
The perl script makes download slower isn’t it ? I upload at 10ko/s :/
[…] tesUpload […]
Hi Tomas,
I tried to download your script but the server is down
tesUpload appears to be incompatible with Internet Explorer 7. Everything works except getting the SID value into the hidden field. For some reason, setting that value fails, the field submits with an empty value, and the PHP never knows there’s been a file submitted.
For everyone who is continually getting “File upload in progress…” with no movement on the progress bar, most likely, your upload.cgi isnt getting called. You will see the failed call by making the iframe in the upload_form of upload_helper.php from 0×0 px to 1000×100 px….
To fix this problem, just update your upload_settings.inc file with the cgi-bin url location (ex. “http://yoursite.com/cgi-bin”) NOT a location relative to root on your disk.
Hope this helps.
Dan
Hi there,
I’m having a problem with the cgi script timing out. I’ve removed the target attribute from the form tag in upload-helper.php and now when I try to upload anything, I (very quickly!) get:
CGI Error
The specified CGI application exceeded the allowed time for processing. The server has deleted the process.
I running the script on shared hosting on a windows server using IIS 6.
Any ideas?
Cheers,
Terry
@Cowboy_X
Can you post what you did to get it working in safari? thanks.
I’m having troubles running «upload.cgi» on my server, it stops at the line
use File::Temp qw/ tempfile tempdir /;
… issuing «Can’t locate File/Temp.pm in @INC (@INC contains: …». Obviously, my Perl installation doesn’t have the module File::Temp. According to a little research, this Perl module is «installed as a standard module in most (but not all) Perl distributions for managing the safe creation of temporary files.»
Is there any workaround to this?
Thank you and best regards
Meaulnes Legler
Zurich, Switzerland
For tesupload to work with the 1.5 final version of Prototype, I had to replace this line in upload.js:
new Ajax.PeriodicalUpdater({},’/inc/classes/fileprogress.php’,{’decay’: 2,’frequency’ : 0.5,’method’: ‘post’,'parameters’: ’sid=’ + sid,’onSuccess’ : function(request){updateProgress(pb,request)},’onFailure’:function(request){updateFailure(pb,request)}})
with this:
new Ajax.PeriodicalUpdater('’,'/inc/classes/fileprogress.php’,{’decay’: 2,’frequency’ : 0.5,’method’: ‘post’,'parameters’: ’sid=’ + sid,’onSuccess’ : function(request){updateProgress(pb,request)},’onFailure’:function(request){updateFailure(pb,request)}})
Don’t know whether this is a standard issue or not. But it helped in my case.
I have a problem with the CGI script. The tempfile gets CHMOD 600, and I can’t make PHP change the CHMOD when the file is moved to its final destination.
And I don’t know any Pearl.
Can I make the CGI script write the file in CHMOD 644?
Any chance someone wants to post some Coldfusion code that works with this?
Hi Tomas,
we are using your script tesUpload in our websoftware. It works fine but the upload is very,very slow. If we do an upload via FTP or HTTP on the same machine the speed is 10 times faster.
What could be the reason for that?
Many thanks for your answer,
Matthias
Matthias (and everyone else with the same problem):
This is fixed in the latest version (1.1) but in the old version a line of code used for testing was accidentally released in the final version (actually, it was in the release-version of megaupload and I didn’t notice it when I made my changes in that code). Anyway, the line is in upload.cgi and looks like this:
select(undef, undef, undef,0.35);
Just remove it and uploads should be 10 times faster. It’s relly good for when you’re testing uploads on a local machine though, so I kept it as a setting in the latest version. You might also want to keep it in if you want to limit the speed of uploads for some other reason, like bandwidth considerations.
1.) In my Windows 2000 system, since $ENV{DOCUMENT_ROOT} doesn’t work in Perl, I have to manually set $docroot.
2.) All my settings are correct, but I still have a very slow upload speed and the script never
puts the uploaded file in the “uploads” directory.
3.) Daniel Starin’s suggestion of January 16th, 2007, for everyone who is continually getting
“File upload in progress…” with no movement on the progress bar, didn’t work for me.
I still could not see the failed call by making the iframe in the upload_form of
upload_helper.php 1000px X 100 px.
4.) In Windows, once an upload has begun, the only way to kill the perl process is with a “kill” utility. A “Cancel File Upload” button would be very useful.
5.) Tomas, your suggestion of Feb 21/07, didn’t help, probably because of other issues I am noting here. A 1 KB file never uploaded.
6.) The .js file “prototype.js” was not in the ZIP I downloaded. Where is it?
7.) In my IE6 browser the text in the textarea is cut off on the right side by a DIV width limitation , when I write in the box.
Thank you for all your efforts. I hope to hear back from you.
hi everyone,
i tried this script but i got the following errors from the error log of apache:
[Fri Feb 23 12:40:55 2007] [error] [client 127.0.0.1] Premature end of script headers: upload.cgi, referer: http://localhost/work/librerieZIP/tesupload/html/upload-async.php
[Fri Feb 23 12:40:55 2007] [error] [client 127.0.0.1] CGI.pm: Server closed socket during multipart read (client aborted?)., referer: http://localhost/work/librerieZIP/tesupload/html/upload-async.php
i saw that temporary files r uploaded in ./tmp but seems not move in ./uploads
i use windows prof system, version of php5,apache2.2 and perl5.8
suggestion?
thks
Great upload script and progress bar! a snap to setup and seems to work very well for large files > 100 MB.
** NOTE ** be sure to comment out the “sleep” line in upload.cgi or your uploads will take forever! See Thomas’ note above from 2/21/07.
Windows 2K IIS 5
Cant get the script put the uploaded file in the “uploads” directory. The tmp file is created but it is never moved ot the final location.
All permissions are correct. I dont know enough to debug the cgi script.
Looks like I have another failed attempt at getting a progress meter working….this must be the 4th or 5th attempt at using a script that will allow me to specify the final location.
As I make to add file[type] ?
Thanks for the script!
One suggestion would be to ‘chmod g+rw’ the file that’s put in $upload_dir
That way, so long as the group ID bit is set on $upload_dir, a user other than the PHP user (e.g. an ftp user) can delete/rename the files in that directory.
In order to make the resulting file RW by the group, edit receive_helper.php and modify the rename function on line 44 to be:
if(rename($q[’file’][’tmp_name’][$i], “$upload_dir/$file_name”.”_tmp”))
{
copy(”$upload_dir/$file_name”.”_tmp”,”$upload_dir/$file_name”);
unlink(”$upload_dir/$file_name”.”_tmp”);
chmod(”$upload_dir/$file_name”, 0660);
}
You would think that issuing the chmod straight after the rename would work, but chmod complains that the file doesn’t exist. The extra file copy step fixes that problem.
I downloaded the file and tried to open with winzip but it gives error “error reading
header after processing 0 entries”. Probably there is nothing in the file. But the ssize is
17 kb What is wrong. Can somebody help me? I need to put a progress bat at my site www.gooclip.net
thanks a lot
Akis
Hi,
I am testing tesupload.CGI program. and have a permission 0600 problem.
Is it possible to write TMP file with 0666 permission ?
So it solves the problem…
Any idea, i am still finding any solution…
Thanks in advance
Kursat
Hi,
I found a solution for 0600 permission problem.
Just add this line to upload.cgi. The permission of temp file will be changed.
($tmp_fh, $tmp_filename) = tempfile(DIR => $tmp_dir);
add below line
chmod 0644, $tmp_filename or &bye_bye (”Can’t change permission: $!”);
while() {
print $tmp_fh $_;
}
have nice day.
bye-KURSAT@
Hi ..
I got “Can’t write-lock numfile:” error.
Is it something to do with chmod of cgi and temp dir?
Current chmod is 755 for both .
Please help me …
[…] Have a look around, the file upload needs improvment, possibly with the aid of a cgi script, Tesupload looks good for now…. All will be considered when I work on it next… Might be in 4 hours, might be 4 months! http://dump.sonuku.com/ […]
Hi everybody !
I am actually implementing testupload to provide a web interface to upload localy big files, permitting external users to have access to this files.
This works fine (i’m using apache2 on Debian and i comment out the line select(undef, undef, undef,0.35)
Until a certain size, upload is enough quick but when i’m uploading a very big file (begining on 500MB) the server craches and shows an error page…
do i need to change php.ini values to permit longer script init ?
Also, when i upload a big file, there is long time even when upload is over while temp files are created (i can see it looking in temp dir) and the file seems to be duplicated 2 times before the script is over and before the file to moved to final dir…
Is there a way to improve the time needed when then upload is done for the files to be moved to final dir ?
Thanks anyone for your answer !
http://1.zpornstars.info x
aristocrat vodka…
ka-ka-sh-ka 5077969 This site contains relevant information about aristocrat vodka….
hogan nick…
ka-ka-sh-ka 5077969 hogan nick friends…
meat loaf discography…
Actual news on meat loaf discography category….
I installed the script and it works great for all files below ~50 MB.
For some strange reason, whenever bypassing the 50 MB border, that is selecting a file > 50 MB and clicking “upload” the script ceases to work.
My php config allows for files up to 128 MB and all files (even larger ones, about 25 MB or so) BELOW ~50MB work just fine.
Whenever I select a file > 50 MB it won’t even start to upload the file, no temporary data is written at all. After clicking “Start upload” the browser behaves normally and says “Upload in progress…” though nothing happens, no progress bar, no temporary data, no error.
Does anyone have an idea to solve the issue? Tomas?
Any help would be really appreciated.
Jo
I solved the issue: It was a flaw in the upload_settings.inc
Script works fine, Thank you very much for it.
We need to change to starting the upload when ’submit’ is clicked, not just run after the input type=file chooser. I need to validate some other form fields have been set first.
HELP:
I can’t fiqure out how to successfully take the onchange=”beginAsyncUpload” out of the textarea->async_upload_form and add it into the button for submitUpload.
[…] http://tomas.epineer.se/tesupload/ […]
A demo would be really nice
[…] tomas.epineer.se » tesUpload […]
Hi there.
How to find out, how fast the upload is?
[…] AW: Progressbar fr Upload Oder man verwendet beispielsweise tesUpload (Upload ber Perl). Gre, Matthias __________________ Gib einem Menschen einen Fisch, und er wird fr einen Tag satt. Lehre ihn Fischen, und er wird ein Leben lang satt. For every complex problem, there is an answer that is short, simple and wrong. Pessimism is safe, but optimism is a lot faster! Experiment: Kohlkopf (Erklrung) […]
Dude, love the script. One thing I noticed when I went to install was that your links to the qstring, signal, etc files in the upload cgi are relative to the cgi directory…thus, seemed to be pointing to cgi-bin/tmp for me instead of docroot/../tmp, where my servers tmp was. Anyway, just wanted to point out the inflexibility of these lines, seems fairly flexible just from solidifying the links by prepending the docroot to them.
Anyway might be something I’m overlooking, just found it more flexible as far as its depth in the filetree for keeping it behind protected dirs for CMS’s or whatever.
Other than that, kicks ass! keep up the good work:)
Cheers,
- Brent (fire.minded.design)
I am trying allready for two days, but it does not seem to work the qstring file stays empty & i think the problem is there
OK After struggeling for a while( 2 days) on windows system I got it to work. Opening binary files in windows need special treatment as they are written differently so they must be opened in binary mode to do this in perl after some digging on the internet I found it. You must use binmode
search for the following in upload.cgi
open(TMP,”>”,”$post_data_file”) or &bye_bye (”Can’t open temp file”);
after that add
binmode TMP;
so it will look like
open(TMP,”>”,”$post_data_file”) or &bye_bye (”Can’t open temp file”);
binmode TMP;
do the same for the following line
open(STDIN,”$post_data_file”) or &bye_bye(”Can’t open temp file”);
so it will look like
open(STDIN,”$post_data_file”) or &bye_bye(”Can’t open temp file”);
binmode STDIN;
Hope this will help windows users out there I lost all my hair because of this (Just kidding I am bold anyways)
i did all the things right but “http://www.puntoparquets.com/metro/heroes/read_settings.php”
The Author, you - genius…
http://srubibablo.com
There was merrily!
Very nice script
I noticed that the «upload.cgi» took about 30% of CPU and the ajax response take about 20seconds with big Files ~650MB
On Debian, Local, AMD Athlon 64 3500+, 1GB PC-3200 Ram, apache2 and php 5.2.3 upload speed was ~10MB/s
to find out how fast the upload is you can use this
Put the following lines at the end of «fileprogress.php» before «echo»
and print out the var $speed on the way you want.
//***************************************************************/
//Upload Speed
function parseSize($size){
$i=0;
$iec = array(”B”, “KB”, “MB”, “GB”, “TB”, “PB”, “EB”, “ZB”, “YB”);
while (($size/1024)>1) {
$size=$size/1024;
$i++;
}
return(round($size,1).” “.$iec[$i]);
}
$info_file_time = 0;
if(file_exists($info_file))$info_file_time = filectime($info_file);
$data_file_time = 0;
if(file_exists($data_file))$data_file_time = filectime($data_file);
$upload_time = $data_file_time-$info_file_time;
$speed = parseSize($current_size/$upload_time).’/s’;
//end Upload Speed
//***************************************************************/
car enterprise renta
car enterprise renta
Please, is there here someone that can help me?
The progress bar runs properly but I found some errors with unlink() and rename(). My administrator says the safe mode is disabled. I don’t understand nothing! The link is below:
http://www.musicnetvision.com/tesupload/
I have problems with the chmod of files, because i can upload files, but cannot read the files, so i tried:
chmod 0644, $tmp_filename or &bye_bye (”Can’t change permission: $!”);
But didnt work for me, so i tried:
if(rename($q[’file’][’tmp_name’][$i], “$upload_dir/$file_name”.”_tmp”))
{
copy(”$upload_dir/$file_name”.”_tmp”,”$upload_dir/$file_name”);
unlink(”$upload_dir/$file_name”.”_tmp”);
chmod(”$upload_dir/$file_name”, 0644);
}
But copy return false, i dont have permissions to copy file, i cant understand why php can rename file, but cant copy it to another file.
I have look for a valid solution, but i cant find, please help me.
http://suzma.info/viagra/pink-viagra.php
The script works great im really pleased with it however im having some problems placing multiple forms and progressbars on the same page, ive got it working in IE but FFox doesnt work, any suggestions?
ignore the above post, the problem was todo with the way i had my “submit” buttons, changing them to type=”button” solved the problems
[…] The script has also been given a name, tesUpload, and a permanent home. -Tomas Larsson 10 comments trackback this article […]
Hi, im not getting tesupload to work with xampp for windows xp 32bit and perl-addon any suggestions?
im getting errors like this: “Premature end of script headers: upload.cgi”
[…] http://tomas.epineer.se/tesupload/ […]
Hi,
I see some are encountering chmod problems. I just managed to come out with a workaround.
http://hongjun.blogspot.com/2008/03/solving-tesupload-giving-chmod.html
hongjun
Hey,
great stuff so far
I have a little problem:
I can upload small files. From a file size of 5 MB and more I get an “The maximum upload size has been exceeded” error.
my php.ini:
; Maximum size of POST data that PHP will accept.
post_max_size = 52M
; Maximum allowed size for uploaded files.
upload_max_filesize = 50M
memory_limit = 196M ; Maximum amount of memory a script may consume (128MB)
Any ideas?
Thanks alot,
Alex
Hello,
found the problem myself: It’s not a limit violation from PHP but from Perl in the upload.cgi script.
After adjusting the value everthing is ok.
Thank you!
Alex
Take note of who is ordering appletinis. ,
Hi; I’m getting this error when trying to do a normal upload
Error
Encountered error: Can’t open numfile: No such file or directory
thanks for the script. i were looking for hours since i found a good one.