PHP 弹出文件下载 原理 代码
2024-09-01 07:43:05
- /**
- * @author default7<default7@zbphp.com>
- * @description 演示PHP弹出下载的原理
- *
- * @param $file_name
- */
- function downFile($file_name)
- {
- $file_path = "/tmp/" . $file_name;
- $buffer = 102400; //一次返回102400个字节
- if (!file_exists($file_path)) {
- echo "<script type='text/javascript'> alert('对不起!该文件不存在或已被删除!'); </script>";
- return;
- }
- $fp = fopen($file_path, "r");
- $file_size = filesize($file_path);
- $file_data = '';
- while (!feof($fp)) {
- $file_data .= fread($fp, $buffer);
- }
- fclose($fp);
- //Begin writing headers
- header("Pragma: public");
- header("Expires: 0");
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
- header("Cache-Control: public");
- header("Content-Description: File Transfer");
- header("Content-type:application/octet-stream;");
- header("Accept-Ranges:bytes");
- header("Accept-Length:{$file_size}");
- header("Content-Disposition:attachment; filename={$file_name}");
- header("Content-Transfer-Encoding: binary");
- echo $file_data;
- }
最新文章
- 【BZOJ-4380】Myjnie 区间DP
- mac下配置Qt for Android+iOS
- jquery操作select(取值,设置选中)
- 解决";System.AccessViolationException”类型的未经处理的异常在 未知模块(IIS Worker Process 已停止工作)导致无法连接远程数据库的问题
- sprint3(第二天)
- git rebase 介绍
- Btn要记得对状态进行设置
- 2005: [Noi2010]能量采集 - BZOJ
- http://www.aboutyun.com/thread-6551-1-1.html
- C语言字节对齐
- 关于I/O的那点事
- [zoj 3774]Power of Fibonacci 数论(二次剩余 拓展欧几里得 等比数列求和)
- mini-httpd源码分析-version.h
- ORACLE union order by
- 简谈java 中的 继承和多态
- 关于hue安装后出现KeyError: ";Couldn&#39;t get user id for user hue";的解决方法
- MFC中应用对象的成员:窗口指针m_pMainWnd说明
- rest_framework 跨域和CORS
- simHash 简介以及 java 实现
- Python之socket编程进阶版
热门文章
- BadUSB测试记录
- 使用Arduino模块实施无线信号的重放攻击
- cocos2dx 3.1.1移植安卓apk (lua项目交叉编译 mac环境下)
- LUN挂载到Linux主机后,如何对磁盘进行分区
- C语言SQLite3基本操作Demo
- [LeetCode&;Python] Problem 590. N-ary Tree Postorder Traversal
- PDF软件推荐——Sumatra PDF - imsoft.cnblogs
- hdu2084 数塔 DP
- MySQL--禁用账号和设置账号有效期
- install kde in ubuntu