出于防止恶意或不需要的文件类型的安全目的,我如何从外部/远程文件(也称为 www.someurl.com/video.avi 之类的 url 链接)中识别 mime 类型?我读过有一种使用 cURL 的方法,但如果可能的话,我想找到一个 PHP native 解决方案。
最佳答案
您可以使用 get_headers
例子:
<?php
$headers = get_headers('http://website.com/image.png');
var_dump($headers);
?>
输出:
array(8) {
[0]=>
string(15) "HTTP/1.1 200 OK"
[1]=>
string(35) "Date: Tue, 08 May 2012 07:56:54 GMT"
[2]=>
string(14) "Server: Apache"
[3]=>
string(44) "Last-Modified: Sun, 06 May 2012 23:09:55 GMT"
[4]=>
string(20) "Accept-Ranges: bytes"
[5]=>
string(22) "Content-Length: 707723"
[6]=>
string(17) "Connection: close"
[7]=>
string(23) "Content-Type: image/png"
}
关于php - 在 PHP 中查找远程/外部文件 mimetypes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10492575/