最新下载
热门教程
- 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.*larue**nce.com/2012/05/02/2613.html
相关文章
- 魔兽世界怀旧服Plus黑暗深渊联盟可接取任务一览 12-07
- tevi雷瓦纳斯隐藏招式触发条件攻略 12-07
- 绝区零拉力委托隐藏区域位置汇总 12-07
- tevi终焉的倒计时成就完成攻略 12-07
- 魔兽世界怀旧服Plus暴风城伍德位置一览 12-07
- 魔兽世界怀旧服Plus传递信仰任务攻略 12-07