本文共 1833 字,大约阅读时间需要 6 分钟。
网络存储下载服务器需求配置$file_fullpath = '/home/www/filepath/2011/12/31/abcd.zip'; header('Content-type: application/octet-stream'); @readfile($file_fullpath);
$file_fullpath = '/home/www/filepath/2011/12/31/abcd.zip'; header("Content-Type: application/octet-stream"); $data = fopen($file_fullpath, 'rb'); while (!feof($data)) { echo @fread($data, 8192); flush(); ob_flush(); } fclose($data);
文件的真实地址为 http://www.artbeta.com/filespath/2011/12/31/abcd.zip 下载地址为:http://www.artbeta.com/down.php?filepath=2011/12/31/abcd.zip&filename=abcd.zip 本文档实现效果为: 1、只有通过php的下载地址能够下载并且“零内存”消耗。 2、通过http://www.artbeta.com/filespath/2011/12/31/abcd.zip 真实的路径是不允许下载的。 3、在php里可以进行一写下载权限的处理。
location /down { internal; alias /home/www/filespath; } /* 此段是为了防止直接通过地址访问文件而做,可以作为防盗链*/ location /filepath { internall; }
$filepath = '2011/12/31/abcd.zip'; $filename = 'abcd.zip'; header("Content-Disposition: attachment; filename= '{$filename}'"); header("Content-Type: application/octet-stream"); header('X-Accel-Redirect: /down/'.{$filepath}); header("X-Accel-Buffering: yes"); header("X-Accel-Limit-Rate :102400"); //速度限制 Byte/s //header("Accept-Ranges: none");//单线程 限制多线程
4.更多处理控制
你可以通过一下头信息来配置 X-Accel-Redirect 特性: X-Accel-Limit-Rate: 1024 X-Accel-Buffering: yes|no X-Accel-Charset: utf-8转载地址:http://ohwvb.baihongyu.com/