我尝试了这两个选项:
-
mime_content_type函数
echo mime_content_type($img_path);
-
finfo函数
$finfo = finfo_open(FILEINFO_MIME_TYPE); echo finfo_file($finfo, $img_path); finfo_close($finfo);
,但我遇到了这两种情况的错误
"警告:finfo_file():失败的识别数据0:没有加载魔术文件"
我没有得到这是什么问题?
对于人们对以后的人来说,原始海报可能将外部URL设置为路径 - " mime_content_type"&" Finfo"函数只能在本地路径上进行运行,而不是外部URL。
示例:
// Local file path
echo mime_content_type("image.gif");
将返回:Image/gif
// External file path
echo mime_content_type("http://localhost/image.gif");
将返回"警告:mime_content_type():失败的识别数据0:没有加载魔术文件"
后备版本以及有关这些功能使用的更多信息,请参见php.net的手册:mime_content_type:http://php.net/manual/en/function.mime-content-type.php
finfo函数:http://php.net/manual/en/book.fileinfo.php
看起来$ img_path没有包含任何文件或错误的文件路径。