Re: Error checking on file upload

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Steve,

Thanks a bunch. Must have been "dead brain" today.  I knew that as well as
could look it up using phpinfo().

Althea

>>In your php.ini there are settings for "upload_max_filesize" and also
"post_max_size." These would be causes for case 2. More information:
http://us3.php.net/features.file-upload


On 8/19/05, Peppy < peppy@xxxxxxxxxxx> wrote:
>
> I've been working on a script for uploading a file to a Unix server. I'm
> testing the script and have it coded for error messages using a switch
> statement. One error that I am getting is case 2 "The file is bigger than
> this form allows" and I am wondering what might cause me to get the error
> for case 1 "The file is bigger than this PHP installation allows".
>
> Thank you,
> Althea
>
>
> <form enctype="multipart/form-data" action="getfile.php" method="POST">
> <!-- MAX_FILE_SIZE must precede the file input field -->
> <input type="hidden" name="MAX_FILE_SIZE" value="50000" />
>
> <!-- Name of input element determines name in $_FILES array -->
> Send this file: <input name="userfile" type="file" />
> <br /><br />
> <input type="submit" value="Send File" />
> </form>
>
> ---------------------------------------------
> $uploaddir =
> '/home/httpd/vhosts/foxedge.net/httpdocs/lvs/phpclass/uploads/';
> $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
>
> echo '<pre>';
> if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
> echo "File is valid, and was successfully uploaded.\n";
> } else {
> echo "Possible file upload attack!\n";
> switch ($_FILES['userfile'] ['error'])
> { case 1:
> print '<p> The file is bigger than this PHP installation allows</p>';
> break;
> case 2:
> print '<p> The file is bigger than this form allows</p>';
> break;
> case 3:
> print '<p> Only part of the file was uploaded</p>';
> break;
> case 4:
> print '<p> No file was uploaded</p>';
> break;
>
> }
> }
>
> echo 'Here is some more debugging info:';
> print_r($_FILES);
>
> echo "</pre>";
>
>
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux