|
-
May 2nd, 2008, 05:00 AM
#1
[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.
-
May 2nd, 2008, 05:42 AM
#2
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.
-
May 3rd, 2008, 05:29 PM
#3
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.
-
May 3rd, 2008, 10:18 PM
#4
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.
-
May 3rd, 2008, 10:40 PM
#5
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!
-
May 4th, 2008, 11:52 AM
#6
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
-
May 4th, 2008, 07:35 PM
#7
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.
-
May 4th, 2008, 07:58 PM
#8
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.
-
May 5th, 2008, 08:17 AM
#9
-
May 5th, 2008, 07:24 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|