if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: " /> 欧美精品久久天天躁,欧美黄色性视频,色婷婷国产精品

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

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.');
}
}
?>

php技術php下載文件的代碼示例,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 山阳县| 察雅县| 舟曲县| 台东县| 岳池县| 阳曲县| 北辰区| 泸水县| 色达县| 锡林浩特市| 张掖市| 吉首市| 博客| 慈溪市| 高邑县| 正蓝旗| 永丰县| 哈尔滨市| 汕尾市| 太仆寺旗| 周至县| 循化| 沙坪坝区| 雷山县| 沅陵县| 汤阴县| 汉中市| 隆昌县| 依安县| 武夷山市| 武义县| 左云县| 博爱县| 炉霍县| 临海市| 林口县| 德保县| 兴义市| 海口市| 霸州市| 吴桥县|