[英]Checking if a URL returns a PDF
我需要檢查URL是否使用PHP返回PDF文檔。 現在,我正在使用file_get_mimetype函數。 普通的URL( https://www.google.com/ )返回類型為application / octet-stream,而普通的pdf鏈接( http://www.brainlens.org/content/newsletters/Spring%202013.pdf )返回應用程序/ PDF格式。 但是現在我也遇到了URL,例如http://www.dadsgarage.com/~/media/Files/example.ashx或http://www.wpdn.org/webfm_send/241 ,它也是pdf,但返回application / octet-流。 還有其他URL也可以打開“另存為”對話框,也必須對其進行檢測。
例如:
$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
)
MIME類型可以包括:
application/pdf, application/x-pdf, application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.