一聚教程网:一个值得你收藏的教程网站

热门教程

提高php下载速度的nginx模块XSendfile配置及实例

时间:2022-06-30 18:35:59 编辑:袖梨 来源:一聚教程网

nginx配置文件

server {
        listen 80;
...................
        # 这个是定义读取你的文件的目录的url开头
        location /files {
                internal;
                alias   /home/lvtao.net/upload;
        }
....................
}

写个简单的演示

 代码如下 复制代码
 //down.php?filename=lvtao.jpg
 
// 获取文件名
$filename = $_GET["filename"];

header ( "Content-type: application/octet-stream" );
$ua = $_SERVER ["HTTP_USER_AGENT"];
if (preg_match ( "/MSIE/", $ua )) {
 $encoded_filename = rawurlencode ( $filename );
 header ( 'Content-Disposition: attachment; filename="' . $encoded_filename . '"' );
} else if (preg_match ( "/Firefox/", $ua )) {
 header ( "Content-Disposition: attachment; filename*="utf8''" . $filename . '"' );
} else {
 header ( 'Content-Disposition: attachment; filename="' . $filename . '"' );
}
 
// "files"是和nginx配置文件的 files要一致
header("X-Accel-Redirect: /files/" . $filename);

热门栏目