php实现文件下载更能介绍
时间:2023-08-18 14:30:21
PHP用代码实现文件下载,阅读PHP用代码实现文件下载,我们一般实现下载都是调用url来下载,但是遇到ie能识别打开的文件就不能用这种方式了,比如下载一个图片、html网页等,这时就需要编程来实现,以下php代码可以解决:?if( empty($_GET[ 我们一般实现下载都是调用url来下载,但是遇到ie能识别打开的文件就不能用这种方式了,比如下载一个图片、html网页等,这时就需要编程来实现,以下php代码可以解决:
<?
if( empty($_GET['FileName'])|| empty($_GET['FileDir'])|| empty($_GET['FileId'])){
echo'<script> alert("非法连接 !"); location.replace ("index.php") </script>'; exit();
}
$file_name=$_GET['FileName'];
$file_dir=$_GET['FileDir'];
$FileId=$_GET['FileId'];
$file_dir = $file_dir."/";
if (!file_exists($file_dir.$file_name)) { //检查文件是否存在
echo "文件找不到";
exit;
} else {
$file = fopen($file_dir . $file_name,"r"); // 打开文件
// 输入文件标签
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($file_dir . $file_name));
Header("Content-Disposition: attachment; filename=" . $file_name);
// 输出文件内容
echo fread($file,filesize($file_dir . $file_name));
fclose($file);
exit();
}
?>
标签:php,实现,文件下载
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
asp.net DropDownList实现二级联动效果
2023-07-23 07:48:41
![](https://img.aspxhome.com/file/2023/6/79976_0s.jpg)
Oracle中pivot函数图文实例详解
2023-07-12 22:13:49
![](https://img.aspxhome.com/file/2023/0/64450_0s.png)
PS笔刷,样式,形状、渐变、滤镜载入方式及使用
2007-10-17 11:47:00
![](https://img.aspxhome.com/file/UploadPic/200710/17/2007101711564849s.gif)
JavaScript 中定义函数用 var foo = function () {} 和 function foo()区别介绍
2024-04-16 09:26:51
PyCharm2021最新激活码+激活码补丁(亲测最新版PyCharm2021.3激活成功)
2022-09-18 05:22:03
![](https://img.aspxhome.com/file/2023/2/80772_0s.png)
关于python简单的爬虫操作(requests和etree)
2022-01-08 02:17:27
![](https://img.aspxhome.com/file/2023/8/69568_0s.jpg)
pandas处理csv文件的方法步骤
2022-05-31 10:51:04
![](https://img.aspxhome.com/file/2023/3/83803_0s.png)
Typora自动编号的具体操作
2022-01-21 03:20:18
![](https://img.aspxhome.com/file/2023/8/114688_0s.png)
教你如何使Python爬取酷我在线音乐
2021-02-18 14:13:01
![](https://img.aspxhome.com/file/2023/6/134716_0s.jpg)
Python利用Pydub实现自动分割音频
2022-10-08 22:02:48
Python中的字符串切片(截取字符串)的详解
2023-07-23 20:37:59
![](https://img.aspxhome.com/file/2023/1/60711_0s.png)
Python3.x对JSON的一些操作示例
2022-08-09 00:23:54
Python中enumerate函数代码解析
2023-05-01 09:13:52
Python中if语句的使用方法及实例代码
2022-03-24 07:17:04
![](https://img.aspxhome.com/file/2023/2/98922_0s.png)
OpenCV imread读取图片失败的问题及解决
2021-10-20 06:44:00
![](https://img.aspxhome.com/file/2023/0/92480_0s.png)
MySQL特定表全量、增量数据同步到消息队列-解决方案
2024-01-24 04:36:47
![](https://img.aspxhome.com/file/2023/6/65706_0s.png)
页面中图像格式的选用之我见
2007-10-31 18:11:00
![](https://img.aspxhome.com/file/UploadPic/200710/31/2007103119144423s.png)
Python海龟绘图之绘制趣味简笔画
2023-03-13 09:09:40
![](https://img.aspxhome.com/file/2023/6/133426_0s.png)
mysql事务和隔离级别底层原理浅析
2024-01-28 03:19:35
![](https://img.aspxhome.com/file/2023/1/101551_0s.png)
python实现抖音点赞功能
2023-08-13 04:06:50