php下載文件的代碼示例
更新時間:2012年06月29日 14:32:13 作者:
php下載文件的代碼示例,需要的朋友可以參考下
復制代碼 代碼如下:
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 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;
}
?>
以上代碼是下載代碼
接下來貼一段在線預覽pdf文件的代碼
復制代碼 代碼如下:
<?php
public function fddAction()
{
// get attachment location
$attachment_location = $_SERVER["DOCUMENT_ROOT"] . "/pdf/fdd/sample.pdf";
if (file_exists($attachment_location)) {
// attachment exists
// send open pdf dialog to user
header('Cache-Control: public'); // needed for i.e.
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="sample.pdf"');
readfile($attachment_location);
die(); // stop execution of further script because we are only outputting the pdf
} else {
die('Error: File not found.');
}
}
?>
相關(guān)文章
Zend Framework教程之Zend_Config_Xml用法分析
這篇文章主要介紹了Zend Framework教程之Zend_Config_Xml用法,結(jié)合實例形式較為詳細的分析了Zend_Config_Xml的功能,使用方法及相關(guān)注意事項,需要的朋友可以參考下2016-03-03
Laravel 6 將新增為指定隊列任務(wù)設(shè)置中間件的功能
這篇文章主要介紹了Laravel 6 將新增為指定隊列任務(wù)設(shè)置中間件的功能,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-08-08
thinkPHP+phpexcel實現(xiàn)excel報表輸出功能示例
這篇文章主要介紹了thinkPHP+phpexcel實現(xiàn)excel報表輸出功能,結(jié)合具體實例形式分析了thinkPHP整合PHPExcel實現(xiàn)針對Excel文件相關(guān)操作技巧,需要的朋友可以參考下2017-06-06
使用PHP?MySQL實現(xiàn)數(shù)據(jù)量小的內(nèi)容推薦方法
這篇文章主要為大家介紹了使用PHP?MySQL實現(xiàn)數(shù)據(jù)量小的內(nèi)容推薦方法示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-07-07
解決PHP使用CURL發(fā)送GET請求時傳遞參數(shù)的問題
今天小編就為大家分享一篇解決PHP使用CURL發(fā)送GET請求時傳遞參數(shù)的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10
如何利用預加載優(yōu)化Laravel Model查詢詳解
這篇文章主要給大家介紹了關(guān)于如何利用預加載優(yōu)化Laravel Model查詢的相關(guān)資料,文章通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面跟著小編來一起學習學習吧。2017-08-08

