nginx,apache web服务器支持POST动态下载文件

来源:互联网 发布:matlab解符号矩阵方程 编辑:程序博客网 时间:2024/05/05 01:10

1.后端动态脚本处理下载;

<?phpob_end_clean();header('Content-Type: audio/mpeg');$filename=$_GET['r'];$file='/data/www/down/'.$filename;$filename=$filename?$filename:'R_ACC_LOCATION_ALL.bin';header('Content-Disposition: attachment; filename='.$filename );header('Content-Length: ' . filesize($file));$fp = fopen($file, 'rb');fpassthru($fp);   //此处需要php去磁盘读文件然后传给web服务器,最后在传给客户端,也可以直接用  X-Sendfile 下载文件提高性能fclose($fp);//参考 http://blog.csdn.net/czh1986/article/details/8482384

2. nginx 服务器伪静态设置

 location / {        if (!-e $request_filename)        {             rewrite ^/down/(.*)$ /down.php?r=$1 last;         }      }



3. apache 服务器配置

a. 打开rewirte 模块。

b. 然后在站点目录下面新建 .htaccess  文件

内容如下:

<IfModule mod_rewrite.c>   RewriteEngine on   RewriteRule ^down/(.*)$ down.php?r=$1 [QSA,PT,L]</IfModule>


4. 最终的POST 地址为 http://www.test.com/down/down-test.txt

原创粉丝点击