最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
实现文件下载功能 PHP 代码片断
时间:2022-06-24 17:06:52 编辑:袖梨 来源:一聚教程网
偶尔用用PHP写点这种很小很小的Web程序,还是蛮简单方便的。
PHP实现文件下载功能的代码如下
$base_dir = "/usr/share/nginx/html/";
$myfile = $base_dir . $_GET["file"];
//echo $myfile;
if( ! file_exists($myfile) ) {
echo "file: " . $myfile . " doesn't exist.";
} elseif ( is_dir($myfile) ) {
echo "file: " . $myfile . " is a directory.";
} else {
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . basename($myfile) . '"');
header("Content-Length: ". filesize($myfile));
readfile($myfile);
}
?>
github: https://github.com/smilejay/other-code/blob/master/php/download.php
另外,一个牛人分析一下使用apache/nginx的一些模块让php实现问下下载更加的高效:
http://www.laruence.com/2012/05/02/2613.html
相关文章
- 无畏契约莲花古城怎么打 源能行动地图攻防技巧 07-01
- ps脖颈纹怎么去除? ps2021改善淡化脖子颈纹的技巧 07-01
- 阴阳师图鉴收集特别签到活动第一弹前瞻介绍 07-01
- 王者荣耀孙权是什么定位 新英雄孙权技能定位解析 07-01
- 推荐:币圈专业名词术语汇总小白入门宝典 07-01
- Aptos创始人加入黑岩集团、高盛,参与制定CFTC加密货币监管框架 07-01