1
我想创建一个自定义异常,以基于$_FILES[..]['error']
代码返回正确的消息。CodeIgniter创建新的自定义异常
我已经扩展了CI_Exceptions class
:
class MY_Exceptions extends CI_Exceptions {
function My_Exceptions() {
parent::CI_Exceptions();
}
public function file_upload_error($error_code = UPLOAD_ERR_OK) {
switch ($error_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;
}
log_message('error', $error_code);
return $message;
}
}
但是当我打电话file_upload_error(1)
它说:Call to undefined function file_upload_error()
我该如何解决这个问题?
你的功能是在课堂外定义的吗? – 2013-04-22 11:01:08
向我们展示您在何处以及如何调用此类方法。 – karmafunk 2013-04-22 11:06:18