PHP gurus: file uploads failing silently

Rower_CPU

Moderator emeritus
Original poster
Oct 5, 2001
11,219
0
San Diego, CA
OK gang, let's see if anyone has an answer for something that's kinda stumping me at the moment.

I've got a form that allows upload of video files. I'm setting the MAX_FILE_SIZE parameter dynamically by reading the upload_max_filesize value from php.ini, which is set to 20M currently.

Now, when I upload a file of 19MB, my script to make sure it's the right filetype, rename it and save it works fine. However, when the file uploaded is over 20MB the check script doesn't return any feedback whatsoever, despite the error in exceeding the maximum upload filesize.

Apache shows a PHP error, but it seems to be happening out of the scope of the script. I've tried reading in the $_FILES['name']['error'] values but nothing shows when it exceeds the max size. I've played with the memory_limit value in php.ini, too but that doesn't seem to matter either.

Do I have to set my post_max_filesize (which is 21MB currently) to some ungodly high value to get my scripts to see that the upload exceeds the upload max??

TIA :)
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Fuquay Varina, NC
And double check these settings in your php.ini.

If your max_input_time is not allowing the whole file to upload, you could have unexpected results.

file_uploads
upload_max_filesize
post_max_size
max_input_time
 

Rower_CPU

Moderator emeritus
Original poster
Oct 5, 2001
11,219
0
San Diego, CA
kingjr3 said:
Exactly what error do you see in the apache log?

Also, can you post a snippet of your save code?
Error
[Thu Feb 24 09:52:24 2005] [error] PHP Warning: POST Content-Length of 25261521 bytes exceeds the limit of 22020096 bytes in Unknown on line 0

Script
PHP:
if($_FILES['video']['size'] != 0) {
		if ($_FILES['video']['size'] > $maxupload) {
			$dddd_message .="<p>The uploaded video file is too large.</p>";
		} elseif ($_FILES['video']['type'] != "video/quicktime") {
			$dddd_message .="<p>The uploaded video file is not a QuickTime movie file.</p>";
		} else {
			$vidfile = "$record_id.mov";

			// Copy file
			if (!move_uploaded_file($_FILES['video']['tmp_name'], "uploads/$vidfile")) {
				$dddd_message .="<p>Oops! Could not save video file.</p>";
			} else {
				$dddd_message ="<div class=\"notice good\"><p>Your video was successfully uploaded.</p>";
				$Query = "update $TableName set mediatype='v' where user_id='$user_id' and record_id='$record_id'";
				if(!mysql_db_query ($DBName, $Query, $Link)) {
					$dddd_message .="<p>Oops! The database didn't update your video file correctly.  Please go back to the previous page and re-submit the video.</p><p>If this problem persists please contact the webmaster.</p>";
				}
			}
		}
	}
 

Rower_CPU

Moderator emeritus
Original poster
Oct 5, 2001
11,219
0
San Diego, CA
kingjr3 said:
And double check these settings in your php.ini.

If your max_input_time is not allowing the whole file to upload, you could have unexpected results.

file_uploads
upload_max_filesize
post_max_size
max_input_time
I'm pretty sure it's not timing out since I'm on the same 100Mbit network as the server and I'm testing a 24MB file. The current setting of 60 seconds is plenty for that.
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Fuquay Varina, NC
Definitely not timing out.

It actually seems that apache is validating the size of the file based on your php.ini setting before your script even executes. Its possible that your error_reporting var might be set too low - which is why you aren't seeing the error. You can change this to actually see the error on the page by with modifying the php.ini, or using a .htaccess file, or with the error_reporting() function in your code. Also make sure to double check your display_errors

Either way, I guess it wouldn't hurt to set the filesize to something large and validate length with code. You can also try to add a hidden input called MAX_FILE_SIZE to your html form. Its value would be a length in bytes. Some browsers will read this and enforce file size on the client. The only rule is the hidden input must occur before your file input field.

Otherwise, I got nothing else.

Good luck
 

Rower_CPU

Moderator emeritus
Original poster
Oct 5, 2001
11,219
0
San Diego, CA
Don't think it's error_reporting either - setting it to E_ALL just popped up a bunch of notices about my uninitialized variables but no errors. Right now it's "E_ALL ^ E_NOTICE" to keep it quieter as I test. display_errors is on, too.

I'm already setting MAX_FILE_SIZE based on the upload_max_filesize value, so it's not that either.

Guess I'll try with the huge filesize and set the upload limit in my script. Thanks for helping me double-check everything. :)
 

angelneo

macrumors 68000
Jun 13, 2004
1,541
0
afk
I am not very sure if I can help but perhaps you can try buffering the php script using ob_start() or enabling it in php.ini and check for errors. This isn't a good idea as it might stressed the server too much but it might worth a shot.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.