PHP-通过URL获取文件类型 [英] PHP- Get file type by URL
本文介绍了PHP-通过URL获取文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用PHP通过URL获取文件类型(例如,图像/gif).
I want to get the file type (eg. image/gif) by URL using PHP.I had tried
<?php
$image_path="http://fc04.deviantart.net/fs71/f/2010/227/4/6/PNG_Test_by_Destron23.png";
exif_imagetype($image_path);
?>
上面的代码给我空白页,下面的代码返回"3":
The above code gave me a blank page and the following code returned "3":
<?php
$image_path="http://fc04.deviantart.net/fs71/f/2010/227/4/6/PNG_Test_by_Destron23.png";
echo exif_imagetype($image_path);
?>
我要去哪里错了? 解决:使用Fileinfo获取内容类型
Where am I going wrong? Solved: using Fileinfo to fetch content type
推荐答案
<?php
$image_path="http://fc04.deviantart.net/fs71/f/2010/227/4/6/PNG_Test_by_Destron23.png";
echo exif_imagetype($image_path);
?>
返回3
是因为png
响应类型如maciej所说.
It returned 3
because png
response type as maciej said.
尝试此操作以获得这样的image/png
:
Try this to get like this image/png
:
echo mime_content_type($image_path);
尝试一下:
$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
echo finfo_file($finfo, $image_path) . "\n";
finfo_close($finfo);
这篇关于PHP-通过URL获取文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文