最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
实现文件下载功能 PHP 代码片断
时间:2015-03-08 编辑:简简单单 来源:一聚教程网
偶尔用用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
相关文章
- xampp怎么运行php文件 02-24
- php文件怎么打开?php文件打开教程 02-24
- php 格式种子文件怎么打开 02-23
- php怎么打开exe文件 php文件中如何调用在服务器上的exe文件 02-23
- php文件怎么打开 如何执行php文件 02-22
- php格式怎么打开?php格式种子文件怎么打开 02-22