PHP | IIS | 上传超出大小限制崩溃

In the php.ini file you can state what the maximum size for any file upload should be (html form upload). If the uploads exceeds that size, the user is redirected straight to an ugly default 404.13 error page, like so: http://puu.sh/gl9XU/e96dc5aabf.png

This is obviously not ideal in a live application. Instead I am trying to capture the file in the code and if the file size is past a certain limit, display a friendly error. The problem is, even at the top of the page which handles the request, it is too late. The application errors out as soon as the request is sent, leaving no room to write php code to handle the file.

How do I work around this? I have written code to detect file size, as stated above, the file is executed far before that:

    if($_FILES["file"]["size"] > 8388608){
        $errors[] = "Your file exceeds the maximum file size (8MB)";
        $upload_ok = 0;
    }