国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php下載文件的代碼示例

2024-05-04 23:14:50
字體:
供稿:網(wǎng)友

復(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;
}
?>


以上代碼是下載代碼
接下來貼一段在線預(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.');
}
}
?>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 仙居县| 田林县| 封丘县| 江北区| 英超| 富平县| 深泽县| 扎鲁特旗| 湖南省| 惠东县| 慈溪市| 民权县| 惠东县| 和硕县| 凯里市| 彰化市| 多伦县| 溧阳市| 谢通门县| 渭南市| 舒兰市| 眉山市| 文成县| 延安市| 克东县| 芷江| 南华县| 大方县| 威海市| 横峰县| 汾阳市| 青川县| 喀喇沁旗| 柯坪县| 潢川县| 郁南县| 安陆市| 永德县| 额敏县| 三江| 株洲市|