Results 1 to 10 of 10

Thread: [RESOLVED] PHP File Upload

  1. #1

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Resolved [RESOLVED] PHP File Upload

    I know how to upload files, but I have a question. When uploading a file with PHP/Apache, does it automatically create a zero-filled file of that size, or does the size "grow" as the file is being uploaded?

    I've searched long and hard for a good (and free) progress bar for multiple-file uploads (with no size limits), but I am also trying my own idea. And whether it works depends on the answer to the question...

    It might be a kind of dirty solution but it should work.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP File Upload

    Nice timing. I'm working on a product that requires the same thing.

    The file grows. But there is no elegant (i.e. not requiring a nasty hack) way of retrieving its name until it is completely uploaded, since PHP allocates it a temporary identifier.

    In PHP 5.2+, install APC and do an AJAX callback to a script that calls apc_fetch to return the upload progress. See the following article from IBM developerWorks.
    http://www.ibm.com/developerworks/op...y/os-php-v525/
    The nice part about this solution is that you can engineer it to work if APC is not installed without needing to supply different versions of the front-end code. The bad part is, of course, that it requires PHP 5.2+ and APC.

    The nasty hacky way is to use ini_set to set the temporary upload directory per script instance, and read the length of the file periodically.

  3. #3

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: PHP File Upload

    Thanks penagate. Yeah, I'm not exactly sure yet how I'm going to do it but the idea was to have a PHP script upload the file. But I wasn't sure how I'd pass the $_FILES['whatever']['tmp_name'] and ['size'] to another file which would periodically retrieve the current temp size and file size to display the progress.

    Mind boggling.

    Will definitely check out the article you posted however, I don't think my client's webserver is running PHP 5.2.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP File Upload

    The $_FILES array is not available until the file is completely uploaded.

    The hacky method involves setting a session variable containing the temporary upload directory, finding the temporary file in that directory, and reading its length on an AJAX callback. I haven't tried this, but it would seem to work.

    Another way is to use a lower-level language like Perl, which gives you access to the file before it is completely uploaded.

  5. #5

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: PHP File Upload

    I've been reading into Perl and found a solution but people were commenting that they were having upload problems with files > 100MB. The client will be uploading video files > 300MB. Totaling about 500-600MB.

    What I'm probably going to do is write a very simple PHP upload script just to upload the file and write info to the database. Then write a Visual Basic front-end to upload the files and show a progress bar and he can just use that for it...

    I'm going to try this Perl thing I found and see if I can get it to work. If that doesn't work then I will just have to use VB and hopefully configure PHP/Apache correctly so it can handle uploads of that size.

    What a PITA!

  6. #6
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP File Upload

    there is a flash solution that i just cant seem to get to work. SwiftUpload or something. It works on the site, i just cant get it to work for me. I have talked to pena about it, dont remember what he said regarding it.
    My usual boring signature: Something

  7. #7

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: PHP File Upload

    Wow and I thought I had tried them all. Is SWFUpload what you're talking about?
    http://swfupload.org/forum/news/392

    I ended up purchasing a copy of XUpload PRO which works really well, but the SWF one looks good too especially for being free.

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] PHP File Upload

    I could not get SWFUpload to work properly without crashing Firefox. This might have been a bug in the SWF, or in Flash, but either way it wasn't satisfactory.


    I finished my AJAX script which uses APC, by the way. It works fine and degrades gracefully when either JavaScript or APC is unavailable.
    The nasty hacky way is next.

  9. #9
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [RESOLVED] PHP File Upload

    Quote Originally Posted by penagate
    I could not get SWFUpload to work properly without crashing Firefox. This might have been a bug in the SWF, or in Flash, but either way it wasn't satisfactory.


    I finished my AJAX script which uses APC, by the way. It works fine and degrades gracefully when either JavaScript or APC is unavailable.
    The nasty hacky way is next.
    Will you be sharing it with us?


    Has someone helped you? Then you can Rate their helpful post.

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] PHP File Upload

    It's virtually the same as outlined in that IBM DeveloperWorks article above.

Posting Permissions

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



Click Here to Expand Forum to Full Width