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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用