2017-08-14 106 views
0

這個段應傳輸文件TIFF作案從Web服務器,用戶通過網絡不能轉移或TIFF文件MODI用PHP

header('Content-Description: File Transfer'); 
header('Content-Type: ' . $file_mime_type); 
header('Content-Disposition: attachment; filename="' . $file_name . '"'); 
header('Content-Transfer-Encoding: binary'); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate'); 
header('Pragma: public'); 
header('Content-Length: ' . $file_size); 

# till this moment all is fine 
echo file_get_contents("path/to/file.tif"); 
# script fails on line above, and doesnt reach this place 

當文件格式不TIFF或作案,一切工作正常和客戶端瀏覽器開始下載文件(docx/xlsx/pdf/etc。) 當用戶嘗試下載tiff或modi時,腳本失敗而沒有任何錯誤。 已嘗試print(file_get_contents(「path/to/file.tif」));readfile(「path/to/file.tif」);而不是回聲,結果是相同的

+0

你有MIME類型在你的網絡服務器設置爲TIF? – raphael75

+0

Yeap,配置中的所有類型都被正確設置了,爲時間準備:) – otctynhuk

回答

0

當我開始使用「通用」的Content-Type,一切工作正常

header('Content-Description: File Transfer'); 
header('Content-Type: application/octet-stream'); //universal Content-Type 
header('Content-Disposition: attachment; filename="' . $file_name . '"'); 
header('Content-Transfer-Encoding: binary'); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate'); 
header('Pragma: public'); 
header('Content-Length: ' . $file_size); 

echo file_get_contents("path/to/file.tif");