博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php下载文件的代码示例
阅读量:4566 次
发布时间:2019-06-08

本文共 1232 字,大约阅读时间需要 4 分钟。

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 
/*
*
* 在线预览pdf文件
* edit by www.jbxue.com
*
*/
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.'); 
?>

参考链接:

posted on
2013-08-01 05:28 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/linuxnotes/p/3229182.html

你可能感兴趣的文章
【2019-09-28】少,但更好
查看>>
【2019-09-13】耐心观察是一种技能
查看>>
mysql数据库2-常用命令
查看>>
安卓开发环境搭建(转)
查看>>
Harris角点检测
查看>>
Struts2的处理流程及为Action的属性注入值
查看>>
设计中最常用的CSS选择器
查看>>
Maven项目打包成可执行Jar文件
查看>>
nginx http proxy 正向代理
查看>>
对BFC的总结
查看>>
23醒
查看>>
win7每天出现taskeng.exe进程的解决方案
查看>>
React Children
查看>>
大数据等最核心的关键技术:32个算法
查看>>
Maven多模块项目搭建
查看>>
redis列表list
查看>>
雷林鹏分享: C# 简介
查看>>
ORA-12505: TNS: 监听程序当前无法识别连接描述符中所给出的SID等错误解决方法
查看>>
实用类-<Math类常用>
查看>>
构建之法阅读笔记之四
查看>>