note 89374 added to features.file-upload.errors
| From: | Anonymous at osu1 dot php dot net | Date: | Thu, 05 Mar 2009 02:32:11 +0000 |
| Subject: | note 89374 added to features.file-upload.errors | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151497@lists.php.net to get a copy of this message | ||
Thanks Michiel for the great code! When I tried it I found it was missing a return statement so
here it is with the return statement added:
<?php
class UploadException extends Exception
{
public function __construct($code) {
$message = $this->codeToMessage($code);
parent::__construct($message, $code);
}
private function codeToMessage($code)
{
switch ($code) {
case UPLOAD_ERR_INI_SIZE:
$message = "The uploaded file exceeds the upload_max_filesize directive in
php.ini";
break;
case UPLOAD_ERR_FORM_SIZE:
$message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was
specified in the HTML form";
break;
case UPLOAD_ERR_PARTIAL:
$message = "The uploaded file was only partially uploaded";
break;
case UPLOAD_ERR_NO_FILE:
$message = "No file was uploaded";
break;
case UPLOAD_ERR_NO_TMP_DIR:
$message = "Missing a temporary folder";
break;
case UPLOAD_ERR_CANT_WRITE:
$message = "Failed to write file to disk";
break;
case UPLOAD_ERR_EXTENSION:
$message = "File upload stopped by extension";
break;
default:
$message = "Unknown upload error";
break;
}
return $message;
}
}
// Use
if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
//uploading successfully done
} else {
throw new UploadException($_FILES['file']['error']);
}
?>
----
Server IP: 208.69.120.35
Probable Submitter: 76.8.192.78
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.errors.php
Edit -- https://master.php.net/note/edit/89374
Del: integrated -- https://master.php.net/note/delete/89374/integrated
Del: useless -- https://master.php.net/note/delete/89374/useless
Del: bad code -- https://master.php.net/note/delete/89374/bad+code
Del: spam -- https://master.php.net/note/delete/89374/spam
Del: non-english -- https://master.php.net/note/delete/89374/non-english
Del: in docs -- https://master.php.net/note/delete/89374/in+docs
Del: other reasons-- https://master.php.net/note/delete/89374
Reject -- https://master.php.net/note/reject/89374
Search -- https://master.php.net/manage/user-notes.php