Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Uploading of large files failing 2

Status
Not open for further replies.

OsakaWebbie

Programmer
Feb 11, 2003
628
JP
I have a form that includes <input name=audiofile type=file...>. In my PHP code to process the form, I check "if (is_uploaded_file($_FILES['audiofile']['tmp_name']))" and then copy the file and set other things in my database. The files I want to upload range in size from about 1MB to 3MB. Under about 2MB, they upload fine, but over that (I don't know the exact cutoff - I haven't done a scientific study), the form submission still takes several seconds (so apparently the file is being sent), but when it gets to my code, the is_uploaded_file check returns false. I do not currently have MAX_FILE_SIZE set (I expect someone would ask that) - I previously had it set to 3MB, but when I ran into this problem, I tried raising it to 4MB, then removed it altogether, but it appears to be unrelated. Is there some sort of timeout that I might be running into or something?
 
Have a look at the following section in your php.ini file

Code:
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = "pathtoupload/"

; Maximum allowed size for uploaded files.
upload_max_filesize = 4M

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
My php.ini file? I'm using a hoster, so I have no access to that.

Anyway, since my first post I have discovered that it is definitely related to time, not file size, because sometimes if a file (typically of a size around 1.6-1.8MB) fails one time, I can try it again and it will succeed.
 
there are timeouts specified in php.ini (you can ascertain your hosts default values through a call to phpinfo() and you can normally change these by either uploading your own php.ini file to the directory from which you are running the script (if php is running as a cgi) or by using ini_set().

however the timeouts in php should not normally come into play with timings outside the execution of the script code itself. so filesystem calls, db calls etc all happen outside of the timing loop.

first off is to get the phpinfo() values and make sure that they are not unreasonably low. also examine the [error] element of the $_FILES['elementname'] superglobal

next is perhaps to try another browser. it could be the client timing-out rather than the server.
 
Have you called set_time_limit(0) at the top of PHP script?
It will run the script with no time out.

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Darn, I thought for sure one of you guys had cracked the code! I looked at phpinfo, and found two potential problems:
max_execution_time=30
upload_max_filesize=2M

So I gradually added things at the top of both the PHP file containing the form (which is what still shows during the time it tries to upload) and the one processing the form, until I had all three of the following, but to no avail:
Code:
ini_set("max_execution_time","120");
ini_set("upload_max_filesize","4M");
set_time_limit(0);
I used a 2.3MB file as my test, and I watched the clock - it definitely stopped executing right at 30 seconds (as accurately as I can tell on an ordinary clock).

Am I doing something wrong in my attempt to override the php.ini settings?
 
try being a bit more courageous in the ini_set !

Code:
ini_set("max_execution_time", "360");
ini_set("max_input_time", "240");
ini_set("memory_limit", "8M");
ini_set("upload_max_filesize","7M");

//now echo back out to make sure that these values stick 
phpinfo();

if the values stick ok then try the upload again with these new settings.
 
oops - forgot to add that the set_time_limit and max_execution_time should not impact file operations and do not have any effect at all if safe mode is turned on.

max_input_time does have an impact on file operations. however unless your host has serious memory problems, i would hope this is not an issue.

 
I wouldn't be privy to information about whether my hoster has memory problems, but max_input_time is set to 60 according to phpinfo, and the attempted upload is not lasting more than 30 seconds, so that's not the problem. BTW, safe_mode is off.
 
Also have a look at settings for
Code:
; Maximum size of POST data that PHP will accept.
post_max_size = 16M
in php.ini. But i am not sure whether it can be modifed in PHP script using ini_set().




--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Oops - I didn't see your previous post. Okay, I put your code in exactly as you gave it to me. Checking phpinfo was a good idea, because indeed, things are not behaving:
max_execution_time: local value successfully changed to 360
max_input_time: unaffected (still 60)
memory_limit: no occurrence of the word memory anywhere in phpinfo, so I don't know where to look
upload_max_filesize: unaffected (still 2M)

I also forgot to check IE (I do everything in Firefox if I have a choice) as was recommended earlier. There, it lasted much longer, so the 30 second limit might be something in Firefox. But it lasted 68 seconds before finishing (without success, which is probably due to upload_max_filesize), so unless my clock is way off, max_input_time is not a player.

This isn't a Firefox forum, but if anyone knows anything... And I need to figure out why upload_max_filesize isn't changing when I tell it to - that seems to be the next PHP hurdle.
 
We must have been writing at the same time - I submitted and found a new post by you.
Also have a look at settings for...post_max_size...
The value in phpinfo for that one is already 8M - that should be fine.
 
it seems that you are not being allowed to override the upload max file size by your host.

have you tried the direct method of uploading a local php.ini and then testing phpinfo()? so long as you are running php as a cgi this should work (but the values may still not be overridable). you don't need a full php.ini, just those lines that you want to change from the default.

otherwise you are probably stuck with one or more of:
1. asking your host to change the value for you
2. using webdav or ftp to upload large files
3. using email to upload large files and then use a server script to pull the files off.
4. changing hosts!
 
and another option if you are running apache. insert the file size directive in an .htaccess file in the script directory or one of its parents.

Code:
php_flag upload_max_filesize 8M
 
As far as I know, PHP is running as an Apache module.

This application is running on multiple domains - right now, they are coincidentally on the same hoster (and it is one that was chosen in spite of the fact that they are lousy at responding to email - it is one of only two I know of who have what I need at a price I can afford), but that could change, so I can't write code that depends on hosters setting things the way I want. For now I have been using FTP when necessary, but of course that's not acceptable in the long term either. For anything up to 2MB, I can do it in IE if necessary (or just retry - about half the time a file just under 2MB gets there in 30 seconds on my connection), and realistically, for this application, 2MB should be enough - these are audio files only for learning songs, and the ones that are over 2MB usually repeat lots of stuff or have a long instrumental section - if I chop it down to only what is relevent, rather than being lazy and just putting up the big file as is, it'll probably be better anyway.

In the future I imagine others wanting this program and uploading their own audio - in that case, I'll have to solve the problem, but perhaps by then common file sizes will grow to the point where hosters will have to raise their settings (I'm just doing audio - imagine how people uploading video feel!). Thanks for your help, anyway - you both get a star.
 
the majority of hosts that i have used allow the user to change the settings locally.

the .htaccess method will work for php running as an apache mod. sorry i overlooked this route earlier in the post. the ini_set will not work with this directive and php.ini will not work with an apache module (you can tell whether you are running a cgi from phpinfo()).

the problem is not the time out. it's just coincidence. the diff between firefox and IE is, i suspect, different way that they interact with the sockets but it could also be simply coincidental network issues.
 
Whoa, that time two posts crossed mine in the mail, and one of them contained the solution! :-D Putting the directive in .htaccess caused the 2.3MB file to upload using IE. I'll dig some more regarding Firefox - that should be easy to solve with a little research. Thanks again!
 
And now another crossing of posts - if people try to read this in order, they will get very confused!
the diff between firefox and IE is, i suspect, different way that they interact with the sockets but it could also be simply coincidental network issues.
Earlier I timed it in Firefox three times, and all three times it ran the rest of the script (which redirects to another page when it is done processing, so it's very obvious) right at the 30 second mark, so I was suspecting some sort of setting. But it will take some time to research it, because the help files are in Japanese (which I can read, but quite slowly). I'm an occasional user on the Mozillazine forum, so I might ask over there (it's in English!).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top