note 43208 added to features.file-upload.errors
| From: | unleaded at unleadedonline dot net | Date: | Mon, 14 Jun 2004 10:04:08 +0000 |
| Subject: | note 43208 added to features.file-upload.errors | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-71033@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.errors.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43208
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43208&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43208&report=yes
Search -- http://master.php.net/manage/user-notes.php