Asynchronous file upload
I wanted to use an asynchronous file upload, like the one on gmail. This means that the file is uploaded in the background, allowing you to still use the page while the file is being uploaded. Since the XMLHttpRequest object doesn’t support file uploads, this had to be done using iframes. Whenever the file input changes, the file is uploaded to the cgi-script in a hidden iframe. The cgi-script writes the total size of the upload and the actual uploaded file to temporary files.
The progress bar
When the upload starts, a Prototype Ajax.PeriodicalUpdater object is created. This object calls a PHP file twice every second using AJAX. The PHP file checks the temporary files while they are being written by the perl file, and returns the total progress in percentage of total upload size. The percentage value is used to set the width of the progress bar.
File & Links
You can download the complete source code here. There is no live demo at this point (sorry!). Similar projects are PHP Upload Progress which can’t report total file size and therefore can’t be used to create a progress bar, and Asynchronous image file upload without AJAX (seems to be down at the moment) which has asynchronous upload of files, but no progress bar. Since it always comes up, I’m also going to mention Filechucker, which is pure perl, doesn’t do asynchronous file uploads and isn’t free.
Limitations & Possible improvements
It can’t currently upload two files concurrently in IE or Firefox, but it can in Safari. Haven’t tested other browsers. It requires Prototype at the moment (included in the archive above) which some see as a downside because of its size. It doesn’t report speed of download. Upload speed is printed when using MegaUpload, so porting that to work with this code wouldn’t be difficult.
Update: The script now has a permanent home and a name: tesUpload.

Nice! I am going to blog this on my blog on webstandards / in Slovak language.
[…] Read the full tutorial Technorati Tags: Ajax, Javascript, Tutorial, Tutorials, Form, Uploading, PHP […]
That’s awesome. Thanks! I’ve been trying to set up a web-based family fileshare for a while and this should let me do it. Keep up the good work!
It’s odd, I’ve placed the files in the proper directories, but I can’t get files to upload.
I used firebug to check a little and I found a few things. After setting a file, the script executes, but returns “0″ as progress. Is “/tmp” a typical directory on a shared server web host account? Is it something that needs to be created? … and permissions?
thanks!
Thanks for the FileChucker mention.
In your post you said:
“Without an asynchronous upload we wouldn’t be able to update the progress bar, since the document would lock up while we uploaded the file.”
Unless I’ve misunderstood you, that isn’t true. FileChucker for example does not do its uploads asynchronously (as you mentioned), and it is able to update the document during the upload just fine.
Johnson: If it’s a UNIX/Linux shared server, it normally has a /tmp directory which you might or might not be able to write to. You will get an alert if it can’t write to it though, so that’s likely not the problem in your case. Try (temporarily) removing the target attribute from the form tag in upload_helper.php for debugging purposes. This means the page reloads when the file is uploaded. If you get “500 Internal Server Error” you have a problem with your cgi-script, have a look in the error log. If you get a blank page the script works fine and the problem is someting else…
Anthony DiSante: You are right of course! I’ll update the text accordingly. Thanks!
[…] Thomas Epinner has posted a short tutorial on his blog with something that I’ve heard many a PHP (and just web) developer looking for - a good way to provide multiple file uploads without sacrificing the functionality of the page. Thomas has created a combination of PHP, Ajax, and a backend script to create a method for asynchronous file uploads complete with a progress bar. One of the few things that I find lacking in PHP 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. […]
[…] Una utilidad que puede ir perfecta para cualquier desarrollador es la insercción de un sistema de subida de ficheros, y si encima está a la última pues mejor que mejor. Este sistema implementa una forma de subir ficheros al servidor mediante Ajax, de forma más amigable para el usuario (con barra de estado y todo ). […]
[…] Thomas Larsson hat in seinem Blog ein Tutorial veröffentlicht, in dem erklärt wird wie man einen (multi) Dateiupload mit Ajax und PHP auf dem Server realisiert. […]
[Ajax / PHP] Asynchronous File Upload with AJAX Progress Bar in PHP…
Ignore all the “Web 2.0″ hype that comes with any web application that makes use of Ajax and it simply boils down to making web interfaces deliver at least as responsive an experience as desktop apps did ten or fifteen years ago. (If you don’t belie…
[…] tomas.epineer.se » Asynchronous file upload with AJAX progress bar in PHP […]
Congratulations, it’s very useful!
Well Done
[…] Una utilidad que puede ir perfecta para cualquier desarrollador es la insercción de un sistema de subida de ficheros, y si encima está a la última pues mejor que mejor. Este sistema implementa una forma de subir ficheros al servidor mediante Ajax, de forma más amigable para el usuario (con barra de estado y todo ). […]
Can’t get this to work, several files index.php etc are completly empty, am I being stupid?
Laurence: I just checked and everything seems to be alright. What did you use to unpack the files?
Nope, I can’t get it to work either. It just sits there for a minute and then refreshes and says it’s been uploaded. Was trying to show it off to a friend too, so much for that :p
[…] tomas.epineer.se » Asynchronous file upload with AJAX progress bar in PHP Tutoriel : Créer une barre de progression en AJAX pour le chargement de ficheir avec PHP (tags: php js web2.0 prototype development howto) […]
Moocats: Did you try the steps I suggested to Anthony DiSante above? What browser do you use? What do you mean by ‘[it] says it’s been uploaded’? Did you press submit for that to happen? Are you sure you’re commenting on the upload package you can download from here?
Interesting! I’ve made some test based in the same projects at raditha.com (mega upload) & StickBlog ( for multiple file uploads with only one file form field ), but using Jquery instead of prototype ( more lighter js library ). You can see the results at http://www.obolog.com/upload.php & a little explanation ( in spanish ) at http://obokaman.obolog.com/mensaje/1511
I hope it can be usefull.
Regards!
So when i do a “debug” by removing the target on the helper’s form tag, i see the following displayed:
“%1 is not a valid Win32 application.”
a cgi problem I would assume, Any help is appreciated
OK, well i dont have perl installed so i guess i’d need that. this is annoying. i hate mixing coldfusion with php with perl on iis, its so ugly. but the output is-a very nice-a
At http://tinyurl.com/s26tn you can find an alterate method without the need to patch PHP or use Perl. Just I open a new popup window that monitors the new file being uploaded and shows its growing size. I think it’s perfect to give feedback to the waiting user.
links for 2006-03-14…
Asynchronous file upload with AJAX progress bar in PHP “… the file is uploaded in the background, allowing you to still use the page while the file is being uploaded.” (tags: ajax javascript webdev programming)……
Good articles
Thanks
[…] Finalmente, un par de recursos. El primero, absolutamente enciclopédico: Downloadable AJAX Galleries, Slideshows and Effects recoge una cantidad de galerías, pases de diapositivas y efectos absolutamente espectacular. El segundo, de interés más limitado, es una barra de progreso para subidas de archivos. Technorati Tags: AJAX creación web diseño WordPress […]
awesome, the implementation is beautiful
If you are using this on a shared servers, there may be some directory access problems.
The following mods fixed things for me. Let’s assume the temp directory I have access to is:
/www/u/username/tmp
And the destination for the uploaded files is:
/www/u/username/uploaded
Here are the mods:
file: upload.cgi
change line 43
from:
$tmp_dir=”./tmp”; # if you change this you need to change it in fileprogress.php too
to:
$tmp_dir=’/www/u/username/tmp’; # if you change this you need to change it in fileprogress.php too
change line 190
from:
($tmp_fh, $tmp_filename) = tempfile();
to:
($tmp_fh, $tmp_filename) = tempfile(DIR => $tmp_dir);
Make sure upload.cgi is executable: chmod it 755
file: receive.php
change line 2
from:
$tmp_dir=”/tmp”;
to:
$tmp_dir=’/www/u/username/tmp’;
file: fileprogress.php
change line 18 to:
$tmp_dir = ‘/www/u/username/tmp’;
file: receive_helper.php
after line 6 insert a new line with:
$dest_dir = ‘/www/u/username/uploaded’;
(and make sure that directory exists)
then change line 22
from:
rename($file[’tmp_name’][0], ‘/tmp/uploads/’. $file[’name’][0]);
to:
rename($file[’tmp_name’][0], $dest_dir.’/’.$file[’name’][0]);
For the spelling gods, change “suite” in line 19 to “suit”
AND POSSIBLY…
file: upload_helper.php
Make sure the action target points to your upload.cgi file. Just make it absolute if you have to:
action=”http://www.yourdomain.com/cgi-bin/upload.cgi?sid=”
HTH.
This is a slick little set of scripts! Thanks to the authors!
Dave
I can upload the file using the perl script and see the progress bar. I can submit the form but then I get this error:
Warning: unlink(/tmp/mysid_qstring): Operation not permitted in /home/myaccount/public_html/mydirectory/receive_helper.php on line 13
I get the same error for rename().
I can add a print_r($file) in recieve.php which outputs the file information but no luck in moving uploaded images. I think it may have to do with permissions around the /tmp folder? If I change the line in the perl script to /public_html/tmp or /www/tmp the script fails.
Any ideas? I’ve been hacking away at this for a while now. I am not familiar with perl. Any help will be greatly appreciated
Thanks!
Eric
[…] Barra de progreso con AJAX El artÃculo se ha terminado. ¿Quieres más? […]
Does anyone have a live demo of the functionality? I want to see this thing in action. Sounds very interesting.
Eric:
Create a folder inside tmp named uploads and chmod 777
I am having trouble with my upload. I tried Tomas’s suggestion to Johnson. I did get a 500 error. When I took a look at the log the error is “Premature end of script headers”. Any help would be greatly appreciated.
I have make progress bar on Ruby, but how I can stop periodically_call_remote?
This progress bar look really nice. I tried to run the script on my windows server. The progress bar works and the file is being uploaded to my tmp dir, but once I press the Submit button, I get this error:
Fatal error: Cannot use string offset as an array in \public_html\upload\receive_helper.php on line 20
Line 20: rename($file[’tmp_name’][0], $dest_dir.’/’.$file[’name’][$i]);
Anyone know how to fix this?
Has anyone noticed any issues with the progress bar when setting a doctype of XHTML 1.0 transitional and giving the a xmlns attribute? Seems odd but it definitely is causing the progress bar not to progress in Firefox for Mac at least.
www.eirestudio.net - Excellent Stuff, I am well on my way to learning AJAX
(WinXP Pro / Apache2 / PHP5 / Perl 5.8)
I have same problem as Jeremy. Was getting a 500 error, Apache error log says ‘Premature end of script headers’.
The progress bar progresses, the file uploads. I get _flength and _postdata files in my temp dir.
After reading around a bit I turned on Carp for descriptive errors to the browser and get:
CGI.pm: Server closed socket during multipart read (client aborted?).
I downloaded the latest version of CGI.pm as suggested by some postings elsewhere, but same problem. Other posts suggest it may be a bug in Apache causing CGI.pm to return this error.
Has anyone managed to get this script fully working on Win/Apache?
Any help much appreciated!
Hi Blueskiwi
I had the same problem. Check your temp directory. It is set in upload.cgi and fileprogress.php. My setting is in both changed to:
$tmp_dir = “D:/xampp/tmp”;
Then it worked.
I hope this helps.
Stephan
An addendum and a question to my previous post:
You need to set the temp directory also in receive.php:
$tmp_dir=”D:/xampp/tmp”;
One problem though: receive.php can not find the _qstring file: In
$file = $tmp_dir.’/’.$sid.’_qstring’;
if(!file_exists($file)) {
return false
}
it indeed returns false. The files XX_postdata and XX_flength do exist, though.
It seems that in upload.cgi the decoding of the postdata doesn’t work, the script does not advance further than this line:
open(STDIN,”$post_data_file”) or &bye_bye(”Can’t open temp file”);
(However, no error is triggered).
Any clues?
Stephan
[…] Asychronous File Uploads - Allows you to create an upload script usign AJAX […]
Yep I get exactly the same… the upload works, no error displayed unless I take the target out of the form post to see what’s going wrong once the upload is complete. I also had to change my temp dir to get that far.
Good work finding the offending line. Wish I knew enough Perl to work around it.
By commenting out various lines it seems to me that the open(STDIN,”$post_data_file”) part actually works.
Seems like the line that breaks it is this one:
my $cg = new CGI();
…which I guess is what you meant anyway.
I am getting closer… found that CGI.pm doesn’t die if the files are approx 1kb in size. Maybe there’s some Apache config setting somewhere messing things up.
Also, I had to change upload.js line #34 to read:
if(percent >= “100″) {
…because the file size on disk is bigger than the figure in _flength
(perhaps just for Windows / just for small files ?)
However now my problem is that the _qstring file is empty, which is confusing receive_helper.php
As best I can tell the reason for this is here (upload.cgi):
my %vars = $cg->Vars;
$cg->Vars is not returning any data.
I am running out of expertise (..time …patience) for this. Anyone else got any ideas?
I am having just one problem that I cannot seem to figure out.
It looks like it is loading correctly to the temp directory, but then when I hit submit, my problems look like it is in receive_helper.php, on the following line.
It appears that for the value of $file[’name’][0] = “C:\DocumentsAndSettings…….” where this is the path from my local computer, not the server path. Is this right? It cannot rename the file because the destination path is
/tmp/uploads/C:\DocumentsAndSettings…… and not /tmp/uploads/filename.xxx
Am I missing something? Any help would be greatly appreciated. BTW. This script rocks!
Well, last night I got it working with my application. Since everyone has been so helpful with thier idea’s and suggestions, I will let everyone know what I had to do to get it working with my application. Here are my application notes.
First thing I should let you know is, I am developing a database driven user website where the user logs in and then can upload videos (which is why I needed to find a good progress bar… Kudos to Thomas for what seems to be the best one out there!) However, I needed the progress bar to be able to dynamically select the upload directory based on the current user. When ever you see the variable $curUser, this is simply the name of the current user logged on to my website.
First of all, I had to change the all the temporary directory paths from just ‘/tmp’ to.
This is similar to what Dave Miller suggested, however, my root directory was different than his. Using this instead should work with everyone, and will guarantee that you are at the root directory of your server. I made this change in the following files. Just search for $tmp_dir, and change them accordingly.
fileprogress.php
receive.php
upload.cgi - For this file, I tried several things, but could only make it work if I manually put in the path to my server root in place of ‘/tmp’ (like Dave Miller’s post). I tried using $ENV{’DOCUMENT_ROOT’}, but even that didn’t seem to work. If anybody figures this out, let me know.
The next thing that I had to do was pass around the $curUser to the files. I just used the $_GET method to do this. Starting with index.php, I would find the $curUser (everyone does this differently, so I won’t go into how to do that). and from there made the following changes.
I changed the action=”receive.php” line to the following.
receive.php?curUser=
Then in receive.php I made the following changes.
Changed the line
$file = receive($sid);
to
$file = receive($sid, $_GET[’curUser’]);
Then in receive_helper.php, I made the following changes.
Changed the function declaration
function receive($sid)
to
function receive($sid, $curUser)
I then had to do something to fix my problem from my first post. Here is the couple of lines that fixes that problem.
Right after the line parse_str($qstr);, I put the following.
$str = $file[’name’][0];
$str = substr($str, (strrpos($str, ‘/’) == FALSE) ? (strrpos($str, ‘\’) + 1) : (strrpos($str, ‘/’) + 1));
Then changed the line rename($file[’tmp_name’][0], ‘tmp/uploads/’.$file[’name’][0]); to the following.
rename($file[’tmp_name’][0], $_SERVER[’DOCUMENT_ROOT’].’/’.$curUser.’/’.$str);
And that was pretty much it. I now can upload files in different folders dependant on who the current user is!
A big thanks to Thomas Larsson for this incredible script! And Dave Miller for some really good suggestions.
Correction to the last post… Apparently it didn’t copy one line correctly.
In the file index.php I changed the line
“…
Hope this helps…
Aggggghhh!! Stupid WordPress!!! If you need the exact line, you can email me at
travist349@yahoo.com.
Thanks.
One question?
Now I am trying to change the width of the progress bar. I changed the width of the progresscontainer in upload.css, which changes how it looks, but the actual progress bar still only goes until it hits about 100px and then shows the file as uploaded. I would like for the progress bar to fill the entire resize value that I placed in upload.css. Does anybody have any suggestions?
Thanks.
Travis,
Thanks for posting the code for getting the file name from an upload - it helped a lot!
In upload.js change this line:
pb.style.width = percent;
to:
pb.style.width = percent + ‘%’;
Then you can change the width of progresscontainer to whatever you want and the progress bar will fill accordingly. In fact, some browsers require units when declaring the width so it’s best to add % or px to the end of that line anyway.
Thanks William! That worked great!
Has anybody figured out how to show Text in this progress bar (such as the percentage or bytes uploaded)? I am trying to get that working now, and have run into some snags.
[…] Due to the great interest in my little php-upload-with-progress-bar script I have now created a sourceforge project for it and released a new version of the code, based on all the great feedback in the original blog post. The new version can be downloaded here. The changes are mostly to make it easier to get started with the script. If you’ve already got it working, don’t bother downloading this one. […]
I’m trying to run this script, but i keep getting internal server error 500.
my temp dir will be a folder called temp located in the same folder as the file upload.cgi (on my server i can run cgi scripts from any directory).
my error log shows me the same errors every time…
Cwd.pm: Subroutine Cwd::fastcwd redefined at /usr/lib/perl/5.8/XSLoader.pm line 91.
upload.cgi: Name “main::file_upload” used only once: possible typo at upload.cgi line 179.
upload.cgi: Name “main::content_type” used only once: possible typo at upload.cgi line 78.
Premature end of script headers: /home/xxxxx/xxxxxx/upload.cgi
File does not exist: /home/xxxxx/xxxxx/internal_error.html
Any Ideas?
nevermind, got the perl part working
I posted this to the Sourceforge site already. But hoping it will get noticed more quick here.
I get the following error when I tried to implement tesupload. Conventional php upload works just fine. I’d appreciate if you could point me in the right direction.
Warning: rename(/tmp/L9EAf2iJGZ): failed to open stream: Permission denied in /home/httpd/../httpdocs/receive_helper.php on line 37
Warning: rename(/tmp/L9EAf2iJGZ,/home/httpd/../httpdocs/tmp/style.inc.css): Permission denied in /home/httpd/../httpdocs/receive_helper.php on line 37
Thanks for your project.
Howard
Hello,
i try to get this tool working for 3 hours ago and nothing is working fine
I have copyd the hole decompressed things in my webroot:
/daten/htdocs/snitch.lan/htdocs/upload/
then i change the settings file for my needs:
temp dir /daten/htdocs/snitch.lan/htdocs/upload/tmp and /daten/htdocs/snitch.lan/htdocs/pics for my uploads. The same path for the cgi-bin dir: /daten/htdocs/snitch.lan/htdocs/upload/cgi-bin/
If i open index.php he says error, can’t find upload dir, if i create the uploads folder in /tmp (system temp!) he can find it and write to it.
But after a form change in giving a file he hangs and no status returns
Please give me a hint for setting this up.
Isn’t it possible to give him absolutepathes for all 3 dirs?
Regards,
snitch
if i remove the target attribute in the form in upload_helper.php, nothing happens too.
Please Help!
Greets
Snitch
tomas.epineer.se » Asynchronous file upload with AJAX progress bar in PHP…
Someone at Smarking has bookmarked your post….
For all of you who are running this on a Win32 box add binmode(FILEHANDLE) to the PERL script wherever data is written to a file.
E.g.:
open(TMP,”>”,”$post_data_file”) or &bye_bye (”Can’t open temp file”);
binmode(TMP);
Then the posted data gets written correctly to the TMP-File and the CGI-Module could successfully decode the posted data.
The problems mentioned by Blueskiwi above disappear
hi tomas…
i need to hire someone to write (or to help me write) a custom web app based around your ajax uploader. would you be interested?
thanks…
zack
Dear Florian,
That change did the trick… You are my hero!!
Just wondered, do I need it on this line as well:
sysopen(FH, $monitor_file, O_RDWR | O_CREAT)
or &bye_bye (”Cannot open numfile: $!”);
binmode(FH);
…Seems to work either way so I guess I’ll leave it off.
Um… the file upload works now but the progress bar doesn’t.
I fixed it by changing lines in the javascript, adding a parseInt to the responseText and changing percent = “100″ percent >= 100 (I made it >= due to an earlier problem with rounding on small files)
…and, I seem to be operational now!!
[…] I recently found a cool script to truly create an "upload progress bar" that will add a missing feature to http file uploads. So whenever you upload a file from your website to the webserver, you will see a progress bar that show you the current status of your upload. He notes that there are two ways around this situation - a patch from Pdoru that has to be applied directly to the PHP install or his method - calling a remote page via an iframe to handle the upload itself. The script sends off the data from the upload form to this other script via the iframe (XMLHttpRequest doesn’t support file uploads) and the Prototype library comined with a PHP script check the file’s upload status and advance the progress bar along. […]
There is a minor bug in recive_helper.php
this line
rename($q[’file’][’tmp_name’][0], “$upload_dir/$fn”);
must be:
rename($q[’file’][’tmp_name’][0], “$upload_dir/$file_name”);
This caused that filename submited by windows systems was bad named.
Sorry about my bad english.
:)
It’s very useful! Good topic
[…] Asychronous File Uploads - Allows you to create an upload script usign AJAX […]
I cannot read the source code. Are the phps zend encoded ot something ?? They look like binary files.
Upload-Status mit PHP…
anzuzeigen ist nicht mit PHP-Code allein möglich. Wenn das eigentliche Script aufgerufen wird, ist bereits alles gelaufen. Nun gibt es mindestens seit mitte 2004 einen Patch für PHP. Dieser wurde aber über ein halbes Jahr auf der PHP-Entwicklerliste…
Hello, I keep getting an error from my CGI file in my error log. I took the target out, and got a 500 Internal error, the error in the log was:
Premature end of script headers: /xxx/xxx/xxx/xxx/xxx/upload.cgi
I have all the files in place, appending ?test prints out everything okay with perl.
I’ve got an linux box.
Could someone shed some light on this issue?
Marco
how add the name of the file uploaded to a mysql database?
Great work
Ciao
Tonyz
Hi, please review Xupload upload progress bar http://www.sibsoft.net/xupload.html I think you will find some useful features, it also have free version. Let me know if you will have any questions. Thanks
Hi, please review Xupload upload progress bar (http://www.sibsoft.net/xupload.html). I think you will find some useful features, it also have free version. Let me know if you will have any questions. Thanks
Florian Schoeppe,
I second Bluskiwi. Your comment about binmode makes everything work like a champ. I was getting frustrated!! Thanks!
I came across this script about six months back (or so) and I decided to completely rewrite the JavaScript so that it does not include Prototype - the library was too big for my tatstes. I also rewrote it to use JSON for error handling and reporting. You might want to take a look at it: http://www.seemysites.net/projFolder/uploader . It has worked great for the projects that I have used so far. Comments and requests are always welcome in the forum, as well.
As far as the 500 error goes, you might want to set the file permissions of the PERL script to 755 in order to run it.
Thanks, this works great! The only problem I’m running into is if onFailure callback is called (ie: if the file you’re trying to upload is too big). Then, I get stuck in an endless loop of “The maximum upload size has been exceeded” alert dialogs!!
Any ideas? The sooner the better, because this is for a project I’m working on for a client and it’s already late!
Thanks!
Hi everybody!
I can’t understand why the cgi script works fine on my local servers but when I try it on my remote server it creates a temporary file without read permission for group and others (rw——-).
The temporary _flength, _postdata, _signal and _qstring files are fine with right permissions (rw-r–r–) instead the uploaded file hasn’t.
Can someone imagine why it works bad on my remote server?
Thanks, bye
carlo
a few questions:
can this handle 200MB, 250MB, and 300MB uploads?
are there any limits to file size of uploads?
Will it work the same on an https site?
thanks
Hi,
Is it there a way to modify the scripts that upload of 2 files is possible (one after the other) with one submit button ?
multipart-form alows that ….
Good work there, buddy!
Great. I have just uploaded the script and configuret it, and it works great.
And like some other users of this script, i am also wondering if this script can handle uploads of for example 200 MB
[…] tesUpload [tomas.epineer.se] […]
Hello mitch, can you share us how you fix the problem with the 500 error - premature end of script headers?
Thank you very much
Hi there,
Is there a place where I can download the script?
Thanks
Hallo,
where is the download link for the script?
Kann man sich mittlerweile irgendwo eine Demo anschauen?
[…] Asynchronous file upload with AJAX progress bar in PHP (tags: ajax php upload webdev) […]
anyone know how to get the total size of a file before it is totally uploaded in coldfusion?
[…] report the progress of a file upload You can leave a response, or trackback from your own site. RSS 2.0 […]
[…] http://labs.beffa.org/w2box/demo/ http://www.obokaman.com/mensaje/1596/ http://tomas.epineer.se/archives/3 http://www.raditha.com/megaupload/ […]
Florian Schoeppe,
You’re the best..
Thanks a mucho..
I need to add a progress bar on my website http://www.gooclip.net or http://www.youtubemovies.net Can someone help me with a tip. Program is in php.
[…] Finding PHP Upload Progress Bar http://pdoru.from.ro/upload-progress-meter/ http://tomas.epineer.se/archives/3 http://www.devpro.it/upload_progress/ […]
is there a way to show the % of file completed ?
the normal upload is working fine, but asynchronous Upload seems having problem.
progress bar never seems to move and if i click submit, alert javascript and saying that “File upload in progress…..”.
I wait for very long time, but still no progress bar is moved.
Any help?
i got it worked. Awesome!
Wow, thats what am looking for and thats awesome..
but, i do get files uploaded in file format adn around 4 files are being uploaded now the problem is how do i RETRIEVE the files i have uploaded…
am unable to retrieve the files and the actual content, because i will move the uploaded file to a safer place in my server..
Thanks in advance
Hi, ich benutze dieses Tool jetzt in meiner Community seit ca. 2 Monaten. Hat immer gut funktioniert und wird von den Benutzern gut angenommen. Weiter so…
Andi
www.tiary.de
Thank you for this amazing Tutorial!
www.creative-dizayn.net
Nice Tutorial
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)
[…] Read the full tutorial Technorati Tags: Ajax, Javascript, Tutorial, Tutorials, Form, Uploading, PHP […]
Hi
I am using the script and it works. The issue which I am facing is that uploads are maxing out at 8kbps Though we have a plenty of bandwidth to the machine. can anyone help
Thanks
Hi
I have also the problem that the uploaded files are chmod 0600. how do i get them to 0755?
thanks for the script!
I am having the problem that gives me: Error: PHP can’t write to temp dir ().
I am using WAMP on Windows XP Pro. I am setting my map to the default tmp($tmp_dir=”../tmp”; #temporary directory, must be writable by both cgi-script and php scripts). I really hope you guys can help me. I already installed PERL on WAMP too.
Arjen
When I leave the line select(undef, undef, undef,0.35); line in the upload.cgi file the progress bar works no probs, but when i remove it the progress bar doesn’t show. I ran some tests and I have found the minimum sleep time the progress bar will work with is 0.05 seconds, select(undef, undef, undef,0.05);
I have only tested this on files under 2MB though because that is the max I can upload at the moment, but is this normal? Is there a minimum file size required before the progress bar will show?
[…] Read the full tutorial Technorati Tags: Ajax, Javascript, Tutorial, Tutorials, Form, Uploading, PHP […]
For those who can’t access uploaded files with a browser because they are chmod:ded wrongly: I have found a solution by mixing from some comments on the php.net, about chmod(). Inside php code chmod might not work as the owner of the file could be other than the php user, so this solution uses ftp functions in php.
Here it is. Put it in receive_helper.php around line 43, after the comment:
Have you ever thought about adding ‘resume upload’ feature? Some time ago I’ve made such, but using java applet - which sends ‘POST’ pieces to php script, that makes file appending…
I created a variation of this for my particular Programming environment Aestiva HTML/OS and it has worked perfectly on all major bowsers until Safari 3 came out.
I had put off trying to troubleshoot until today. As a first step I updated to Thomas’s most recent code that removed the prototype requirement. As I was working throught the code to see if I could determine the problem I found this snip…
It seemed like everything below xhr.open never seemed to fire, but I wasn’t getting any errors. So I looked up what that “true” was supposed to do and found out it determined if the open request was async or not. I set it to false and everything started working again.
I wonder if my solution could be improved upon?
Terry Riegel
Call to undefined function: file_get_contents() getting this error when reading upload_settings.inc
Hey, very nice but it uploads very slow on my server! Is there a way to get it faster?
Thanks,
mike
Hi
I am getting
Error: PHP can’t write to temp dir ().
I am using wamp server 1.7.4
where is the PHP.INI config file in this
Please help
[…] Read the full tutorial Technorati Tags: Ajax, Javascript, Tutorial, Tutorials, Form, Uploading, PHP […]
hi,wow!
nice tutorial
but we cant get code
can u preview thats tutorial code
Without cgi, Can we upload the file/image with progress bar using AJAx & PHP?
I am using latest version, asyncronous example works well, but in trying normal upload i get page cannot be displayed error. the files are in the temp directory but not moved to final directory.
The URL on page cannot be displayed error is like:
http://myserver/cgi-bin/upload.cgi?sid=fb033f139e627a35399b111f966aa913&target=\/receive.php
Any idea on where to startlooking?
This is on a windows 2003 box with Apache 2.2.8, Activeperl 5.10 and php 5.2.5
online casino 2 win online…
bitterest Murphy!hillsides substances preferably …
This is an good idea, but very little documentation..
I have the progress bar working, the files get uploaded to the server in the tmp folder i specified in the settings file, but they do not get copied to the final location..
There is no errors produced by either perl or PHP so i am a bit at a loss why this is not working.
I have permissions of 0755 on everything, i even hacked the perl to make the uploaded file in the tmp folder 0755 too, but still the php fails silently…
Any clues anyone?
Tadalafil fedex….
Tadalafil. Low blood pressure cialis tadalafil faint. Sanafi tadalafil. Low blood pressure cialis tadalafil….
@ mike
edit upload.cgi
look for the line:
while (read (STDIN ,$LINE, 4096) && $bRead < $len )
I adjusted mine from 4096 to 2048000
and that seemed to do the trick