我需要检查URL是否使用PHP返回PDF文档。现在我正在使用file_get_mimetype函数。普通URL(https://www.google.com/)返回类型为application / octet-stream,而普通pdf链接(http://www.brainlens.org/content/newsletters/Spring%202013.pdf)返回application / pdf。但现在我也遇到了像http://www.dadsgarage.com/~/media/Files/example.ashx或http://www.wpdn.org/webfm_send/241这样的URL,它也是pdf但返回application / octet-stream。还有其他URL也打开了另存为对话框,也必须检测到它。
答案 0 :(得分:4)
例如:
$url = "http://www.dadsgarage.com/~/media/Files/example.ashx";
if (in_array("Content-Type: application/pdf", get_headers($url))) {
echo "URL returns PDF";
}
print_r(get_headers($url));
返回
Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: private, max-age=604800
[2] => Content-Length: 194007
[3] => Content-Type: application/pdf
[4] => Expires: Tue, 09 Dec 2014 09:40:20 GMT
[5] => Last-Modified: Wed, 07 Aug 2013 16:46:30 GMT
[6] => Accept-Ranges: bytes
[7] => Server: Microsoft-IIS/8.0
[8] => Content-Disposition: inline; filename="example.pdf"
[9] => X-AspNet-Version: 4.0.30319
[10] => X-Powered-By: ASP.NET
[11] => X-Provider: AWS
[12] => Date: Tue, 02 Dec 2014 09:40:20 GMT
[13] => Connection: close
)
答案 1 :(得分:1)
mime类型可能包括:
application/pdf, application/x-pdf, application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf