博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
文件下载【PHP】
阅读量:7174 次
发布时间:2019-06-29

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

  hot3.png

简单实现PHP控制文件下载;

调用方式:http://127.0.0.1/temp/index.php?id=c479ec02fec10bbd8af1568b197b19aa

'123.doc', '47eb4fe400e2eef3f8a404ad3ce3e33f' => '456.doc', '5cd8cb481b2571dd443675eb8253592c' => '789.doc', ); #检查id是否在指定的列表中 if(array_key_exists($_GET['id'],$file_list)){ #文件名 $file_name = iconv('UTF-8','GB2312',$file_list[$_GET['id']]); #文件路径 $file_path .= $file_name; #检查目录文件是否存在并输出 if(file_exists($file_path)){ header('Content-Description:FileTransfer'); header('Content-Type:application/octet-stream'); header('Content-Disposition:attachment;filename='.$file_name); 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_path)); ob_clean(); flush(); readfile($file_path); exit; } }}?>

转载于:https://my.oschina.net/Jacker/blog/73293

你可能感兴趣的文章
为什么要进行项目总结呢?又如何进行项目总结呢?
查看>>
iOS——重写Cell分割线
查看>>
window与linux下,php的redis扩展安装
查看>>
VirtualBox虚拟机网络设置
查看>>
Mongodb 之 安全权限控制
查看>>
httpclient发送网络请求
查看>>
可自动切换登录不同系统测试实例
查看>>
jQuery Validate
查看>>
Building IKEv1 and IKEv2 on CentOS 7
查看>>
Zabbix server is not running:zabbix access denied
查看>>
我的友情链接
查看>>
linux下的软硬链接
查看>>
【JAVA的 IO流之FileInputStream和FileOutputStream】
查看>>
远程连接mysql 授权方法详解
查看>>
FreeBSD网络配置
查看>>
@synthesize window=_window; 的理解
查看>>
Greenlet理解要点
查看>>
罗森伯格应邀主讲CDCC百家大讲堂38期
查看>>
How to Install Nextcloud 13 Server on Debian 9
查看>>
[深入理解文件系统之一] IO系统调用
查看>>