Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I catch this error? (POST Content-Length ...)

Tags:

php

While uploading image I'm getting this error: (max 8mb an image)

Warning: POST Content-Length of 14259306 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

How can I display this message customly? I mean I want to put that error in CSS style. thank you....

like image 835
Ali Demirci Avatar asked Feb 16 '12 16:02

Ali Demirci


3 Answers

In case of common errors you need to set error handler. See here for details. BUT

If errors occur before the script is executed (e.g. on file uploads) the custom error handler cannot be called since it is not registered at that time.

like image 114
Vessimir Avatar answered Nov 05 '22 15:11

Vessimir


Maybe you wanna try something like this.

if (isset($_SERVER["CONTENT_LENGTH"])) {
    if ($_SERVER["CONTENT_LENGTH"] > ((int)ini_get('post_max_size') * 1024 * 1024)) {
        die('<script type="text/javascript">window.open("some page youre gonna handle the error","_self");</script>');
    }
}
like image 40
Batu Zet Avatar answered Nov 05 '22 15:11

Batu Zet


if ($_SERVER['CONTENT_LENGTH'] < 8380000) {
 ... your code
} else {
    ... Your Error Message
}

You can also increase the maximum size in the php.ini

post_max_size = 60M
upload_max_filesize = 60M
like image 35
Kevin Avatar answered Nov 05 '22 15:11

Kevin