Rectangle 27 0

html PHP: File extension is empty when user uploads image with unallowed extension?


<?php
IF (isset($_POST['submit'])) {

    $err = "";
    $mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/jpg', 'image/png', 'image/x-png'); 
    $imgexts = array('gif', 'jpeg', 'jpg', 'png'); 

    IF (!empty($_FILES['file']['name'])) {

        $img = $_FILES['file']['name'];
        $temp = $_FILES['file']['tmp_name'];
        $ext = strtolower(substr(strrchr($_FILES['file']['name'], '.'), 1));// file ext.
        $info = @getimagesize($_FILES['file']['tmp_name']); 
        $imgw = $info[0]; // width 
        $imgh = $info[1]; // height 
        $mime = image_type_to_mime_type($info[2]);

        IF (!in_array($ext, $imgexts)) { 
            $err .="<li>File type (".$ext.") is not supported. (Only ".implode(", ",$imgexts).")</li>"; // Non-supported file type 
        }ELSE{
            // 
            IF (!in_array($mime, $mimetypes)) { 
                $err .="<li>Mime type (".$mime.") is not supported. (Only ".implode(", ",$mimetypes).")</li>"; // Non-supported mime type 
            }

        }

    }ELSE{ 
        $err ="<li>Select a file to upload (".implode(", ",$imgexts).")</li>";
    }


    IF (!empty($err)) {

        echo '<p>Errors:</p><ul>'.$err.'</ul>';

    }ELSE{

        // good to go

    }

}ELSE{

    // form not sumbitted 


}
?>
Note