php下載檔案的程式碼範例

高洛峰
發布: 2023-03-02 16:30:02
原創
1072 人瀏覽過

複製程式碼 程式碼如下: 
$file = 'monkey.gif'; 

if (file_exists($file)) { 
header('Content-Description: File Transfer'); Type: application/octet-stream'); 
header('Content-Disposition: attachment; filename='.basename($file)); 
header('Content-Transfer-Encoding: binary'); 
header('Content-Transfer-Encoding: binary'); 
header('Expiresheader(Expiresheader( : 0'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Pragma: public'); 
header('Content-Length: ' . filesize($file)); 
ob_clean(); 
flush(); 
readfile($file); 
exit; 

?> 
?> 程式碼 
複製程式碼 程式碼如下: 
public function fddAction() 

// get attachment location 
$attachment_location = $_SERVER["DOCattachment location 
$attachment_location = $_SERVER["DOCattachment_OT"pdf if (file_exists($attachment_location)) { 
// attachment exists 

// send open pdf dialog to user 
header('Cache-Control: public'); // needed for i.e. /pdf'); 
header('Content-Disposition: inline; filename="sample.pdf"'); 
readfile($attachment_location); 
die(); // stop execution of further script because we becaly outare theon pdf 

} else { 
die('Error: File not found.'); 


?> 

相關標籤:
php
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!