Created
July 2, 2018 06:56
-
-
Save achepukov/686af2fbe99ba577c2ea6009b140cb00 to your computer and use it in GitHub Desktop.
Php upload errror -> string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* UploadErrorMessage | |
*/ | |
class UploadErrorMessage | |
{ | |
/** | |
* @var int upload error code | |
*/ | |
protected $code; | |
/** | |
* @param int $code upload error code | |
*/ | |
public function __construct($code) | |
{ | |
$this->code = $code; | |
} | |
/** | |
* Get string representation of error | |
* @return string | |
*/ | |
public function __toString() | |
{ | |
switch ($this->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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment