Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: upload progress

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default upload progress

    I may add to this post later as issues arise, but is there a way to use PHP or a simple bit of javascript to maybe refresh the page every 5 seconds to display how much of a file has been uploaded or what percentage of the file has been uploaded?

    I am looking to modify an existing script as opposed to installing one that has already been created like uber_uploader.

    Another question. Let's say I have a basic upload program and have not placed any limits on it. Are there defaults to how much large of a file I can upload? For example, if I use fireftp I am reasonably sure I can upload a 100MB file, but would I be able to do the same with php or are there default limits built in that would need to be altered with php.ini to modify the upload limits? It appears that there are size limits even though I have not set any.
    To choose the lesser of two evils is still to choose evil. My personal site

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    The answer to the upload file size limit has been found. There are some default values in the php5.ini or php.ini depending on what you use.

    upload_max_filesize=50M default is 2M
    post_max_size=50M default is 8M

    If these values are not stated then the default values are implied.
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I believe that the limits are just the defaults and you can change them if you like. There is no inherent limit on how large a file you can upload, but from experience working with video files (I've uploaded 1GB files fairly often), you absolutely do not want to have it over an http connection. The main reason is that you cannot restart the upload if it dies, and over that much time even on a strong connection it's likely that something will go wrong enough of the time (1/3? at best...) that you'd want to avoid it.

    Note that also PHP does not reject a file until it's completely sent: if the user waits for a 50mb file to upload then finds out there's a 2mb limit, they'll be upset.

    There are ways around this: use java, flash or other programs that can actually handle this kind of thing and work around it.

    But for most uses (that is-- not video, huge audio files or really big uncompressed images, and no archives/programs), you'll be fine and rarely go over 5mb.



    As for tracking an upload in progress, that's extremely difficult.
    Even without the limits of Ajax/JS/PHP it is hard. And that's why computer time is never real time in the progress bar: 2 hours to go, 30 seconds to go, 4 days to go, and then at some point it actually finishes, unrelated to the computer's guess.

    The basic method is to constantly call back to the server to find out how much of the file is there. It's possible and not that hard, but hard to keep stable.
    But that's for a real programming language on a real connection.

    Using Ajax to track PHP from a current upload is all but impossible: you need to find where the temporary file is being stored, SOMEHOW identify which one is actually your file (it seems like the newest one should be, but what about many users at the same time), and then also compare this to the full filesize-- how do you get that? Maybe in JS?

    Using ActiveX, Flash, Java applets, etc., you may be able to get more info. With basic Ajax and PHP, you're going to have lots of trouble.

    If you can just use an existing script and not use your own code, it's a much simpler process.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    The basic method is to constantly call back to the server to find out how much of the file is there.
    This is really all I want to do.
    But that's for a real programming language on a real connection.
    Are you talking about C++?
    To choose the lesser of two evils is still to choose evil. My personal site

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'm talking about anything that actually has access to both the user's computer and the server at the same time, not a fake system of Ajax and calls to PHP.

    For example, I never finished the project (no need, just testing), but I created something like this in PHP. The difference is that the uploads weren't through HTTP, but through the FTP functions within PHP (php sending to another server) AND the php was executing as an .exe on my computer, not as a hidden process on the server.

    The issue isn't the language, but it's security/access limitations.

    In theory you could program a space ship in Javascript, but good luck actually getting that to work from a webpage. And here it's practically that hard-- you don't really have access to what's going on for the server.

    You *CAN* try to get the temporary filename by pinging the server after the upload starts and you can try to compare that to expected progress, etc., but it's really very complex.

    To put it in perspective, it would take a very serious programmer who knows a lot about server configurations and how PHP works at a fundamental level to be able to really do this well.

    It's probably possible to throw something together that will approximate it, but it'll be very hard.

    I wouldn't bother attempting this myself-- I don't think I'd be able to do something very accurate.

    It's a tempting idea, of course, and an interesting puzzle, but that's as far as I've ever gotten with it.


    The main place where this all gets messy is that when you start uploading a file NOTHING happens except that it's dumped temporarily somewhere on the server. You can find that place (it's based on how the server/php are configured), but to figure out which file it is and what it's doing is incredibly hard. Then to loop through Ajax and get the server to tell you what's going on with the file will only get you a rough idea of the progress, etc.



    You might want to look into uploading the file through Javascript. I have no idea if that's actually possible (that's why even gmail implements flash in this case), but if you could do an ajax upload that might give you permission to see the progress.


    In theory this is very easy to do-- the number must exist somewhere. But in practice the format of JS vs. PHP (among other things) makes it nearly impossible.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    certainly more involved than I was initially thinking.

    You mentioned that there were a few alternatives. What would you recommend as far as a simple or minimalistic upload program for a website; flash, java or whatnot. My initial requirements are certainly not fixed. In fact I notice that the Opera browser already does this with its built in "speed" and "total" meters.

    This is all for my own personal use and not for the general public.
    To choose the lesser of two evils is still to choose evil. My personal site

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Then I'd say use Opera

    I don't have any good suggestions.

    If you're doing this as a fun experiment to see what you can figure out, good luck.

    If you're doing this for a practical application, you're probably just better off finding an existing script.


    A java applet will have the most access (and also be the most awkward in a few ways, like crashing some computers-- they are definitely not 'smooth').

    Apparently flash can do it as well, though I don't know the details.


    The choice I guess depends on your ability/interest to learn those two options. Flash is probably easier but Java would be more powerful.... tradeoff.


    For just "simple" if you're willing to skip all of this, then you can easily do it with PHP alone (and some JS if you want).

    If you must have a progress bar, it's going to be very difficult.


    The easiest way is to look at an existing script and see how that works, or just use the script.


    Here's a case where re-inventing the wheel probably won't help you.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Now, I don't have any real code to back my theory up but I see it as this.
    Have this progress bar:http://www.dynamicdrive.com/dynamici...lprogress3.htm in an iframe on the page that your uploading and set a meta tag to auto refresh every 5 seconds or so. Have the PHP get the file size of the temporary file size and divide by the total file size, then multiply the answer by 100:

    Code:
    $amount_uploaded = filesize($uploadedfile['name']);
    $decimal_uploaded = $amount_uploaded/$uploadedfile['size'];
    $percent = $decimal_uploaded*100;
    something like that (please fix my code if necessary).
    That's the percent done, then just send the percent done to the progress bar:
    Code:
    <script>
    setCount(<?php echo $percent; ?>);
    </script>
    ... that refeshes every 5 seconds or whatever.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Have the PHP get the file size of the temporary file size
    Everything about what you've said is fine. BUT-- how would you accomplish that one "simple" bit? You can figure out where the temporary files are stored, but if multiple uploads are occurring around the same time, then how would you figure out which one is yours? If you can manage that then it is possible. But I've casually looked into it and from what I can tell it gets a random name and there's no way to associate it with anything aside from *maybe* the file creation time and the submission of the script, but even that is just a guess.


    I'd actually be more than willing to try to help figure this out, but I'm hesitant because I really don't see a way to make it work well just in having to find which temporary file is correct.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Use Flash and PHP. Since this is for only personal use you can use the tutorial with explanation found here
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •