确定文件扩展名不适用于大文件

时间:2014-05-07 09:12:13

标签: php

我已对以下脚本进行了编码,以便在上传任何非图像文件或任何大于4 MB的图像时显示错误。现在,当我上传任何大于4 Mb的图像或上传任何小视频文件时,它会显示错误,这很好。但是当我上传一个更大的文件(比如大约50 MB)时,它不会显示任何错误。相反,它只是在registration.php中显示空白页面。它应该被重定向到' complete_profile.php'如果有任何错误。这只发生在大文件中..为什么会这样?

registration.php中的代码:

if(isset($_POST['answerbox1']) && isset($_POST['answerbox5']) && isset($_POST['answerbox6']) && isset($_POST['sex']) && isset($_FILES['hiddenfilebutton'])){

        $img_name = $_FILES['hiddenfilebutton']['name'];
        $img_temp = $_FILES['hiddenfilebutton']['tmp_name'];
        $a = explode('.',$img_name);
        $allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
        $img_extension = strtolower(end($a));
        unset($a);
        $img_size = $_FILES['hiddenfilebutton']['size'];
        if(!getimagesize($img_temp)) {
            $error = 'Invalid image';
            $_SESSION['error'] = $error;
            header('Location: ../../../complete_profile.php');
        } else if($img_size > 4000000) {
            $error = 'Image should be less than 4 MB';
            $_SESSION['error'] = $error;    
            header('Location: ../../../complete_profile.php');
        } else if(!in_array($img_extension, $allowed_ext)) {
            $error = "Unsupported image format";
            $_SESSION['error'] = $error;    
            header('Location: ../../../complete_profile.php');
        } else {
            header('Location: ../../../desk.php');
        }
    }

0 个答案:

没有答案