dsa88886666 2016-07-25 04:52
浏览 33
已采纳

PHP中的实时服务器不支持文件类型函数

I have application on a live server where I want to check upload file is image or not. In my localhost and other live server following functions are working except one current server.

1. mime_content_type($file);
2. $file_type = exec("file $file");
3. $finfo = new finfo(FILEINFO_MIME);
   $file_type = $finfo->file($_FILES['image']['tmp_name']);

Some are deprecated, some are disabled due to security reasons. Can I have other methods/techniques to get file type which is used to check whether upload file is image or not?

  • 写回答

1条回答 默认 最新

  • dourao1896 2016-07-25 04:58
    关注

    You can use getimagesize() to determine if the uploaded file is image or not.

    Use it like this,

    $image_info = getimagesize($_FILES['file']['tmp_name']);
    if ($image_info === FALSE) {
       die("Uploaded file is not an image.");
    }
    

    getimagesize() function will determine the size of any given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag and the correspondent HTTP content type.

    It will return FALSE in case of uploaded file is not an image.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?