[ciapug] File Upload

Carl Olsen carl-olsen at mchsi.com
Tue Feb 21 14:40:57 CST 2006


Here's one of the user comments from the PHP online manual regarding file
uploads

jason
09-Jan-2006 05:08 
Regarding empty $_FILES and $_POST arrays when uploading files larger than
post_max_size:

Tucked away in http://us3.php.net/manual/en/ini.core.php#ini.post-max-size
is this nugget:

"If the size of post data is greater than post_max_size, the $_POST and
$_FILES superglobals are empty. This can be tracked in various ways, e.g. by
passing the $_GET variable to the script processing the data, i.e. <form
action="edit.php?processed=1">, and then checking if $_GET['processed'] is
set."

This may seem like a bug. You'd expect something like UPLOAD_ERR_FORM_SIZE
to be set. But you just two empty superglobals.

I've seen it submitted to bugs.php.net twice and it's been marked as bogus
both times.

Carl

-----Original Message-----
From: ciapug-bounces at cialug.org [mailto:ciapug-bounces at cialug.org] On Behalf
Of Barry Von Ahsen
Sent: Tuesday, February 21, 2006 9:15 AM
To: carl-olsen at mchsi.com; ciapug at cialug.org
Subject: Re: [ciapug] File Upload

for file uploads, I found this once on php.net (I don't see it now)

if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
switch($_FILES['file']['error']){
	case 0: //no error; possible file attack!
	$errtxt .= "There was a problem with your upload.";
	break;
	case 1: //uploaded file exceeds the upload_max_filesize directive in

php.ini
	$errtxt .= "The file you are trying to upload is too big.";
	break;
	case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was

specified in the html form
	$errtxt .= "The file you are trying to upload is too big.";
	break;
	case 3: //uploaded file was only partially uploaded
	$errtxt .= "The file you are trying upload was only partially
uploaded.";
	break;
	case 4: //no file was uploaded
	$errtxt .= "You must select a file for upload.";
	break;
	default: //a default error, just in case!  :)
	$errtxt .= "There was a problem with your upload.";
	break;
}
}

-barry


Carl Olsen wrote:
> I ran into an unusual situation today creating a file upload script.  I
have
> the php.ini settings for memory_limit, upload_max_filesize, and
> post_max_size all set to 10M.  I have a form with a hidden field
> MAX_FILE_SIZE just before the file input box set to 10000000 (10 million
> bytes, slightly less than 10M).  I have a function that checks both the
file
> extension and the file type, so it only allows files of certain types to
be
> uploaded.  I get unusual results.  When I upload most files that do not
fit
> the required type, it give me one of my custom error messages.  When I
> upload a file that is too big, it doesn't do anything (MAX_FILE_SIZE
> prevents the form from posting).  However, when I upload a file with an
.exe
> file extension that is 54MB, I get a machine error that starts out "PHP
> Warning" at the bottom of the page.
> 
> What I would really like to do is figure out how to write some PHP code to
> intercept the machine error and display a custom error on the page, but it
> appears to be outside the scope of any PHP code I can insert into the
page.
> Has anyone seen this before?
> 
> Carl Olsen
> 
> _______________________________________________
> ciapug mailing list
> ciapug at cialug.org
> http://cialug.org/mailman/listinfo/ciapug


_______________________________________________
ciapug mailing list
ciapug at cialug.org
http://cialug.org/mailman/listinfo/ciapug



More information about the ciapug mailing list