偶尔用用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
PicACG/哔咔漫画网页版入口地址-PicACG/哔咔漫画最新可用的网页版入口地址
126.com免费邮箱快速登录-126邮箱网页版一键登入
e站ehviewer网页版直达-ehviewer官网最新进入口
漫蛙官网入口免费下载最新版本-漫蛙漫画app安卓苹果双端安装包获取
谷歌浏览器手机版官方下载2024最新安装包-谷歌安卓手机浏览器最新版官方下载入口
jmcomic网页版最新入口-jmcomic网页版解锁入口