php下載文件的代碼示例
更新時(shí)間:2012年06月29日 14:32:13 作者:
php下載文件的代碼示例,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
<?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;
}
?>
以上代碼是下載代碼
接下來(lái)貼一段在線預(yù)覽pdf文件的代碼
復(fù)制代碼 代碼如下:
<?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)文章
php結(jié)合GD庫(kù)簡(jiǎn)單實(shí)現(xiàn)驗(yàn)證碼的示例代碼
這篇文章主要介紹了php結(jié)合GD庫(kù)簡(jiǎn)單實(shí)現(xiàn)驗(yàn)證碼的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
PHP控制前臺(tái)彈出對(duì)話框的實(shí)現(xiàn)方法
本文給大家分享通過(guò)php echo出javascript腳本來(lái)控制前臺(tái)彈出對(duì)話框的效果,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看下吧2016-08-08
淺談PHP檢查數(shù)組中是否存在某個(gè)值 in_array 函數(shù)
下面小編就為大家?guī)?lái)一篇淺談PHP檢查數(shù)組中是否存在某個(gè)值 in_array 函數(shù)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06
tp5 實(shí)現(xiàn)列表數(shù)據(jù)根據(jù)狀態(tài)排序
今天小編就為大家分享一篇tp5 實(shí)現(xiàn)列表數(shù)據(jù)根據(jù)狀態(tài)排序,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-10-10
PHP中file_get_contents函數(shù)抓取https地址出錯(cuò)的解決方法(兩種方法)
本文通過(guò)兩種方法解決PHP中file_get_contents函數(shù)抓取https地址出錯(cuò),需要的朋友可以參考下2015-09-09
ajax+php實(shí)現(xiàn)無(wú)刷新驗(yàn)證手機(jī)號(hào)的實(shí)例
下面小編就為大家分享一篇ajax+php實(shí)現(xiàn)無(wú)刷新驗(yàn)證手機(jī)號(hào)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12

