?
Solved

pure PHP upload progress bar

Posted on 2006-04-27
17
Medium Priority
?
1,963 Views
Last Modified: 2012-06-22
i'm having a hard time finding any kind of upload progress bar that will work in my case.

every example i see requires installing a patch, etc. etc. on the server.

well, my site is hosted on godaddy.com so i don't believe there is a whole lot of control that i have over this.

the biggest problem seems to be... i don't know how to retrieve the amount uploaded during the upload.

i could start with an iframe as an upload forms target. a <div> to display progress. and hopefully be able to send requests to a php file that can get the uploaded amount and then send a response.

am i asking for the impossible? these sample scripts seem to be a nuisance for my particular situation.
0
Comment
Question by:Jeremy Daley
  • 8
  • 5
  • 3
  • +1
17 Comments
 
LVL 15

Expert Comment

by:m1tk4
ID: 16559072
>> the biggest problem seems to be... i don't know how to retrieve the amount uploaded during the upload.

And unfortunately that's the one you can't solve. Apache (web server) does not pass control to PHP until the file is fully uploaded.
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16559169
so do you know what i might be able to do considering my shared hosting?
0
 
LVL 15

Expert Comment

by:m1tk4
ID: 16559355
>>so do you know what i might be able to do considering my shared hosting?

Yes. Nothing.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16560714
The communication is as follows.

Client makes a GET request for a form which allows the user to upload a file.
Server examines requests and supplies the HTML file or launches the PHP script which creates the HTML and then the server sends this.
Client renders HTML.
User fills in form and selects a file to upload.
User presses submit.
Client makes a POST request to server.
Server starts receiving data and stores the data in its temp location (the specific directory may NOT be accessible to anything other than the web server whilst the upload is taking place.
Server will then launch the handler for the POST once the upload is completed. In the case of PHP, the $_FILES array will be populated.

At no stage does PHP get activated DURING or BEFORE the upload.

Without patching the server, there is no mechanism available.

If the patching was done, the mechanism is non-standard and may not be supported adequately within PHP.
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16561471
okay... tell me this much...

if you were in my situation, and you had many a number of users that would be using your site to upload up to 10Mb Mp3 files... what would you do? an animation of some sort, possibly telling the amount of time that has elapsed?

do you think calling godaddy.com would solve anything? should i switch hosting with someone that YOU know may further help my situtation?
0
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 750 total points
ID: 16561512
http://www.raditha.com/php/progress.php

This uses Perl rather than PHP to deal with the upload. But then passes it all over to PHP when uploaded.

This example uses an auto-refresh to get the details back to the user.

This could be extended to use an AJAX mechanism to not have the page refresh.

But I think you CANNOT do this with PHP alone.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16561518
And this doesn't look like it needs any patches to the server. Just Perl. Which should be there.
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16561613
i've tried this and haven't had too much luck... but then again i wouldn't completely rely on that answer as a base for saying it doesn't work.

the installation instructions are sometimes really vague also and i'm not always sure how to find my temp directory, etc. my hosting account doesn't even have a cgi-bin folder anywhere, but that's not to say i don't have perl support.

i'll look at this even further and see what i can make out of it.

i do want to ask another question though... is there something that i can setup in the form that would stop the upload pretty much as soon as it starts? like if i set up the max_upload_size (not sure if that's the right fieldname), or perhaps the form's enctype, might it upload for a second and then immediately fail allowing me to execute my php and still retrieve file size? can i detect connection speed somehow without it basing itself off of upload progress/elapsed time?

if it was possible, this way, i could get the filesize at least and let the user know an approximate time frame, then send a RE-submittal of the form.

like i said RQuadling, let me look more into raditha's solution, but i may be asking for further assistance for a proper setup. thanks
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16561638
The max_upload_size issue is not guaranteed to be supported by all browsers. It cannot realistically be relied upon.

0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16561936
good point
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16568848
well, i'm certain i have everything required to run megaupload progressbar. my original hosting package didn't have any perl support whatsoever. now i have support for the following:

 - Perl(w/FASTCGI)
 - Python CGI
 - Java
 - Ruby CGI
 - Ruby on Rails(w/FASTCGI)

now i have uploaded all the files required to run the demo on my server to the locations that the installation documentation instructs, but for some reason i keep getting internal server errors.

i have set full access on the cgi bin and also confirmed all the paths to which the files are pointing to. what other reasons might i be getting this error?

(50pt increase)
0
 
LVL 15

Expert Comment

by:m1tk4
ID: 16569101
What you should've really done is close this one and open a second one - remember that EE is both for you to get your problems solved and to leave a good and consistent knowledge base for anyone who might have the same problems in the future. "Packing" one thread with unrelated problems isn't really such a good thing.
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16569156
i don't understand how this is unrelated. my goal is to get an upload progress bar on my site using php.

if using the mega upload progress bar was suggested as a solution to my problem, is it too much to ask for support regarding that particular suggestion?
0
 
LVL 7

Expert Comment

by:CraigHarris
ID: 16570854
You can make a client-side progress bar using JavaScript - whatever you do server side will still need an action performed client side, so it would be difficult to avoid JavaScript anyway ---- you could use AJAX techniques to check the progress of the file IF it is constantly being written to temp folder AND you have permission to read that folder .... otherwise, you need JavaScript to handle the actual upload, which isn't trivial for security reasons.
0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16571143
i pretty much understand that concept... it's the reading of the file's progress that is causing me the strife.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16604115
Not being picky, but you are no longer using PHP to deal with the progress bar.

0
 
LVL 4

Author Comment

by:Jeremy Daley
ID: 16604624
i started with megauploader and switched over to uber uploader. it's all on sourceforge.net.

actually i did start using AJAX to embed the bar into my page and sent requests via JS to the cgi file which returned all the vitals.

it worked pretty good as far as that went... but it was a little quirky dealing with my file and that's why i switched.

hopefully i can now work on ways to speed up the uber uploader. i appreciate your help. thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month15 days, 22 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question