Check picture file type and size before file upload in php

后端 未结 7 1564
走了就别回头了
走了就别回头了 2020-12-09 13:41

I have the following code:

$filecheck = basename($_FILES[\'imagefile\'][\'name\']);
  $ext = substr($filecheck, strrpos($filecheck, \'.\') + 1);
  if (($ext          


        
相关标签:
7条回答
  • 2020-12-09 14:34

    take note that for Internet Explorer, they submit JPEG file's mime type as image/pjpeg - which is different from other browsers.

    Here's a simple function to get your mime type against the file extension:

    function mime2ext($mime){ // mime is like image/jpeg
        $m = explode('/',$mime);
        $mime = $m[count($m)-1]; // get the second part of the mime type
        switch($mime){
            case 'jpg':
            case 'jpeg':
            case 'pjpeg':
                return 'jpg';
                break;
            case 'png':
                return 'png';
                break;
            case 'gif':
                return 'gif';
                break;
        }
        return '';
    }
    
    0 讨论(0)
提交回复
热议问题