猿问
PHP如何检查文件是mp3还是图像文件?
除了检查每个可能的扩展名外,我如何检查文件是mp3文件还是图像文件?
至尊宝的传说
浏览 626
回答 3
3回答
摇曳的蔷薇
您可以使用来识别图像文件getimagesize。要查找有关MP3和其他音频/视频文件的更多信息,建议使用php-mp4info getID3()。
0
0
0
米琪卡哇伊
获取模仿类型的本机方法:对于PHP <5.3,请使用mime_content_type()对于PHP> = 5.3,请使用finfo_fopen()获得MimeType的替代方法是exif_imagetype和getimagesize,但是这些方法依赖于安装适当的库。此外,它们可能仅返回图像模仿类型,而不是magic.mime中给出的整个列表。如果您不想打扰系统上可用的功能,只需将所有四个函数包装到一个代理方法中,该方法将函数调用委托给任何可用的方法,例如function getMimeType($filename){ $mimetype = false; if(function_exists('finfo_fopen')) { // open with FileInfo } elseif(function_exists('getimagesize')) { // open with GD } elseif(function_exists('exif_imagetype')) { // open with EXIF } elseif(function_exists('mime_content_type')) { $mimetype = mime_content_type($filename); } return $mimetype;}
0
0
0
慕田峪9158850
要查找文件的mime类型,请使用以下包装函数:function Mime($path){ $result = false; if (is_file($path) === true) { if (function_exists('finfo_open') === true) { $finfo = finfo_open(FILEINFO_MIME_TYPE); if (is_resource($finfo) === true) { $result = finfo_file($finfo, $path); } finfo_close($finfo); } else if (function_exists('mime_content_type') === true) { $result = preg_replace('~^(.+);.*$~', '$1', mime_content_type($path)); } else if (function_exists('exif_imagetype') === true) { $result = image_type_to_mime_type(exif_imagetype($path)); } } return $result;}
0
0
0
随时随地看视频
慕课网APP
相关分类
PHP
php如何把参数放在Http Request Heade????
1 回答
我要回答