I've used ini_set('post_max_size',"2M")
in my php script to limit uploads file size. it didn't worked (do you know why ? )
So i put these rules on my htaccess
file :
php_value post_max_size 2M
php_value upload_max_filesize 2M
So when i upload a file larger than 2M , my php script shows this error :
Warning: POST Content-Length of 15903708 bytes exceeds the limit of 2097152 bytes in Unknown on line 0
How can i handle this error in an appropriate way ? (something like try catch).
Note : I wouldn't like to hide this error.
In your upload script, have you tried:
if ($_FILES['upfile']['size'] > 2000000) {
$error_message ="Exceeded filesize limit.";
}
Also there is try/catch in php for example:
try{
//your upload script
}
catch(Exception $e){
$error_message = "File did not upload: ". $e->getMessage();
}
From this you should be able to handle any errors how you want
Another solution is a custom error handler:
set_error_handler("warning_handler", E_WARNING);
//your upload script
function warning_handler($errno, $errstr) {
// do someing with your error here
}
restore_error_handler(); // reinstates original error handling
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.