php+nginx实现的文件下载

2009年5月23日 | 标签: ,

发送X-Accel-Redirect头实现直接定位成静态下载

$root_path = ‘/web/www’; //网站根目录
$file_path = ‘/data/t.txt’;  //文件路径

//发送下载的头信息
header(”Content-type: application/x-octet-stream”);
header(”Accept-Ranges: bytes”);
header(”Content-Disposition: attachment; filename=”.basename($file_path));
header(”Content-Length: “.filesize($root_path.$file_path));

//发送文件定位,是相对网站目录的路径
header(”X-Accel-Redirect: “.$file_path);

目前还没有任何评论.