note 89345 added to features.file-upload.errors

From: Date: Wed, 04 Mar 2009 11:15:16 +0000
Subject: note 89345 added to features.file-upload.errors
Groups: php.notes 
Request: Send a blank email to php-notes+get-151437@lists.php.net to get a copy of this message
This is a handy exception to use when handling upload errors: <?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; } } } // Use if ($_FILES['file']['error'] === UPLOAD_ERR_OK) { //uploading successfully done } else { throw new UploadException($_FILES['file']['error']); } ?> ---- Server IP: 89.248.170.61 Probable Submitter: 62.21.214.163 ---- Manual Page -- http://www.php.net/manual/en/features.file-upload.errors.php Edit -- https://master.php.net/note/edit/89345 Del: integrated -- https://master.php.net/note/delete/89345/integrated Del: useless -- https://master.php.net/note/delete/89345/useless Del: bad code -- https://master.php.net/note/delete/89345/bad+code Del: spam -- https://master.php.net/note/delete/89345/spam Del: non-english -- https://master.php.net/note/delete/89345/non-english Del: in docs -- https://master.php.net/note/delete/89345/in+docs Del: other reasons-- https://master.php.net/note/delete/89345 Reject -- https://master.php.net/note/reject/89345 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151437) next »