Re: [請益] Header 下載的一個問題

看板PHP作者 (NidgetGod)時間16年前 (2009/12/18 19:20), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/4 (看更多)
以下做一個php開圖的範例: image.php <?php header( 'Content-Type: image/gif' ); $Filename = '1.gif'; readfile( $Filename ); ?> 直接執行就會跑出圖片來 如果要開 pdf 改一下: pdf.php <?php $Filename = 'manul.pdf'; if( file_exists($Filename) ) { header( 'Content-Type: application/pdf' ); readfile( $Filename ); } else echo 'Sorry, file not exist.'; ?> ※ 引述《JYHuang (夏天到了,冷不起來了說)》之銘言: : 之前寫了一個檔案下載的程式 getfile.php : 利用Header 下載或開啟檔案。 : 不過最近遇到一個情形是 : 如果檔案是還沒有被支援的格式(像是沒灌Acrobat Reader遇到.pdf) : $filename = "manul.pdf" : header("Content-Type:application/pdf"); : header("Content-Disposition: inline ; filename={$filename}\n"); : header("Content-Transfer-Encoding: binary"); : header("Content-Length: ".filesize($filename)); : @readfile($filename); : 在IE下會變成要如何處理"getfile.php"的下載對話框 : Firefox是會出現要如何處理"manul.pdf"的對話框 : 這裡是要讓browser直接開啟檔案 : 請問http header的格式 能不能在browser遇到不認識的檔案時 : 變成下載指定檔案。 : ..還是這又是IE下無解的問題 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.167.224.96
文章代碼(AID): #1BAsLbJl (PHP)
文章代碼(AID): #1BAsLbJl (PHP)