This commit is contained in:
Paula Quispe
2018-11-08 08:42:51 -04:00
parent 63946e5ea3
commit 15ad93368d
5 changed files with 343 additions and 11 deletions

View File

@@ -0,0 +1,57 @@
<?php
namespace ProcessMaker\Exception;
use Exception;
class UploadException extends Exception
{
/**
* @param integer $code
*/
public function __construct($code)
{
$message = $this->getMessageByCode($code);
parent::__construct($message, $code);
}
/**
* Get the message to the corresponding error code
*
* @param integer $code
*
* @return string
*/
private function getMessageByCode($code)
{
// These messages do not have translations because they will be caught in the exceptions
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;
}
}