最新下载
热门教程
- 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
相关文章
- 西瓜影院网页版入口-西瓜影院网页版极速下载 03-10
- 2026火影忍者云游戏官网秒玩直达-火影忍者云游戏极速入口 03-10
- jm网页版官网入口-jm网页漫画官网大全 03-10
- ehviewer网页版ios-E站ehviewer官网最新ios链接 03-10
- 哔咔漫画官网入口-哔咔漫画官网镜像流畅不卡 03-10
- 谷歌浏览器手机版官方下载安装2024-谷歌安卓手机浏览器最新版官方入口地址 03-10