Page 1 of 2
Upload Progress Bar??? HELP!!!
Posted: Mon Sep 04, 2006 10:16 pm
by JustinMs66
hey so i have a working PHP code for a upload form, but i wana make a progress bar for it. so like if it's a pretty big file, people will know how much longer it'l take. here is my current code:
Code: Select all
<?php
$bad_types = array('application/octet-stream','application/x-msdos-program','application/x');
if( in_array( $_FILES['uploadedfile']['type'], $bad_types ) )
{
echo "That File type is not supported.";
}
else
{
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded. here is the link to your file: <a href=uploads/". basename( $_FILES['uploadedfile']['name']). ">". basename( $_FILES['uploadedfile']['name'])."</a>";
} else{
echo "There was an error uploading the file, please try again!";
}
}
?>
Posted: Mon Sep 04, 2006 10:22 pm
by feyd
We've talked about progress bars before. There is nothing native that will do them. Perl can do them as can Flash, Java and ActiveX controls. PHP, by itself, cannot do them.
Posted: Tue Sep 05, 2006 12:38 am
by dibyendrah
If move_uploaded_file() could take the source file as a small chunk and we could loop till the file size and pass the small chunk to the function and display the progress bar. But move_uploaded_file() function takes the source files and do it all and return just a boolean value. I think php.net community should make the function parameters customizable .
Cheers,
Dibyendra
Posted: Tue Sep 05, 2006 12:41 am
by RobertGonzalez
PHP processes on the server. Status bars report on the client. Unless you plan on sending requests to the server during different stages of the upload (which I don't think is possible) you are going to have to use a client side solution. This is probably a job for AJAX or some other DHTML type of technology.
Posted: Tue Sep 05, 2006 12:28 pm
by volka
dibyendrah wrote:If move_uploaded_file() could take the source file as a small chunk[...]
move_uploaded_file already works on the temporary file already created on the server's local filesystem, i.e. the actual upload is finished when move_uploaded_file is invoked.
Posted: Tue Sep 05, 2006 12:31 pm
by Luke
I always throw this solution out there just because it's easy... you could just display an animated gif that says "Loading..." and maybe some sort of loading-type animation. This way at least the user sees that SOMETHING is happening.
Posted: Tue Sep 05, 2006 12:36 pm
by n00b Saibot
The Ninja Space Toad wrote:This way at least the user sees that SOMETHING is happening.
ok and what if the upload fails for some reason... then what do you show to the user

Posted: Tue Sep 05, 2006 12:46 pm
by Luke
n00b Saibot wrote:The Ninja Space Toad wrote:This way at least the user sees that SOMETHING is happening.
ok and what if the upload fails for some reason... then what do you show to the user

umm...
"Sorry... upload failed."

Posted: Tue Sep 05, 2006 12:58 pm
by n00b Saibot
I posted that as a follow-up joke on your line. but seriously if you ask me, then I would change the line a bit, may be to 'Please wait while your file is being uploaded...' and animating something beyond that to achieve the same effect you were talking about. Afterwards, if loading fails then you can show the error to the user — "Your File was not uploaded because <insert reason here>".
I fear we are straying off-topic...
Posted: Thu Sep 07, 2006 11:55 pm
by RobertGonzalez
feyd wrote:We've talked about progress bars before. There is nothing native that will do them. Perl can do them as can Flash, Java and ActiveX controls. PHP, by itself, cannot do them.
This is about as good an explanation as you can expect. Several of us have posted on this subject before. PHP will not take care of status bars. AJAX can, JavaScript can, client-side technologies can. Server-side technologies will not do this for you.
Posted: Fri Sep 08, 2006 3:24 pm
by travist349
Hey guys,
I noticed a lot of people wondering about how to integrate an upload progress bar.
I have implemented this in my site, and I used the
TesUpload by Thomas Epineer. It is a fantastic script that works great!
It uses a colaboration of PHP, Perl, and AJAX to create an upload progress bar that does not require page refreshes.
Let me know if you guys have any problems.
Posted: Fri Sep 08, 2006 6:22 pm
by Ollie Saunders
feyd wrote:We've talked about progress bars before. There is nothing native that will do them. Perl can do them as can Flash, Java and ActiveX controls. PHP, by itself, cannot do them.
Perl?! Really how? What does Perl have that PHP doesn't!
Image: Smurfing ahead
Posted: Fri Sep 08, 2006 6:33 pm
by Luke
ole wrote:Really how? What does Perl have that PHP doesn't!
I'm interested in know that as well... if I recall it was something about hooks?
Posted: Fri Sep 08, 2006 8:18 pm
by Christopher
ole wrote:Perl?! Really how? What does Perl have that PHP doesn't!
Uh ... Larry Wall ... and the ability to monitor uploading files.
The reason it cannot be done in PHP is that PHP is currently unable to comminicate to the submitting script any sort of handle or identifier to access the temporary file. It therefor cannot monitor the upload or pass the info to a monitoring script. With PHP you have to wait until the receiving script runs to check the uploaded file -- and by that time the file is already uploaded.
There was/is a patch for PHP that adds this feature. There are also a long running series of requests and patches to add this functionality to PHP -- one by the author of that patch. None have been accepted so far that I know of. I have not followed it for a while so do know if there are any plans in 6.0 for this.
Posted: Fri Sep 08, 2006 8:24 pm
by Luke
what does scruvy mean?
