We are using post_max_size
and upload_max_filesize
PHP variables to prevent users from uploading big files into our web app.
The thing is that the error me开发者_如何学Gossage that PHP throws is ugly for the users and does not say much (especially for spanish users). So the users report this as a bug or think it is not working.
How can I change this page and show our own page (something more user friendly and in Spanish)?
Thanks a lot!
I think you're looking for set_error_handler().
So something along the lines of (from the manual):
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
if (!(error_reporting() & $errno)) {
// This error code is not included in error_reporting
return;
}
switch ($errno) {
case UPLOAD_ERR_INI_SIZE:
echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
echo " Fatal error on line $errline in file $errfile";
echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
echo "Aborting...<br />\n";
exit(1);
break;
default:
echo "Unknown error type: [$errno] $errstr<br />\n";
break;
}
/* Don't execute PHP internal error handler */
return true;
}
$old_error_handler = set_error_handler("myErrorHandler");
catch the error and output a custom message.
try {
// your code
} catch (Exception $e) {
if($e->getCode() == some code){
$message = 'some message';
}else{
$message = 'some other message';
}
}
echo '<div>'.$message.'</div>'
精彩评论