How to get MIME-type of an image with file_get_contents in PHP

后端 未结 3 1686
梦谈多话
梦谈多话 2021-02-01 22:58

I need to get the MIME type of an image, but I only have the body of the image which I\'ve got with file_get_contents. Is there a possibility to get the MIME type?<

3条回答
  •  遥遥无期
    2021-02-01 23:17

    Yes, you can get it like this.

    $file_info = new finfo(FILEINFO_MIME_TYPE);
    $mime_type = $file_info->buffer(file_get_contents($image_url));
    echo $mime_type;
    

提交回复
热议问题