note 43208 deleted from features.file-upload.errors by curt
| From: | curt@php.net | Date: | Fri, 04 Feb 2005 05:37:06 +0000 |
| Subject: | note 43208 deleted from features.file-upload.errors by curt | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-84500@lists.php.net to get a copy of this message | ||
Note Submitter: unleaded at unleadedonline dot net
----
Note that the above error messages don't catch *everything* (well there is only one other
example I have run into).
An example is when the user enters a dud file into the form, PHP won't return
UPLOAD_ERR_NO_FILE because it has detected a file name, but there is no data associated with it -
and hence when you do your fread or whatever on ['tmp_name'], you will get an error
stating the length must be greater than 0.
So it would be best to also check the length of the file size/string after upload as well using your
own code, an example is:
<?php
// Content uploading. 'none' needed for IE compatability.
$file_data = '';
if ( !empty($_FILES['userfile']['tmp_name']) &&
($_FILES['userfile']['tmp_name'] != 'none' ) )
{
// We encode the data just to make it more database friendly
$file_data = base64_encode(@fread(fopen($_FILES['userfile']['tmp_name'],
'r'), filesize($_FILES['userfile']['tmp_name']) ) );
}
switch (true)
{
// They must specify a document on a new node
case ($_FILES['userfile']['error'] == UPLOAD_ERR_NO_FILE):
case empty($file_data):
echo 'You must select a document to upload before you can save this page.';
break;
/// Now chekc the error messages
case ($_FILES['userfile']['error'] == UPLOAD_ERR_INI_SIZE):
case ($_FILES['userfile']['error'] == UPLOAD_ERR_FORM_SIZE):
echo 'The document you have attempted to upload is too large.';
break;
case ($_FILES['userfile']['error'] == UPLOAD_ERR_PARTIAL):
echo 'An error occured while trying to recieve the file. Please try again.';
break;
}
?>
Notice the @fread to supress the error message associated with the condition I explained earlier.