码迷,mamicode.com
首页 > Web开发 > 详细

让PHP更快的提供文件下载

时间:2015-06-23 17:19:30      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

原文链接: http://www.laruence.com/2012/05/02/2613.html

 

我们可以使用Apache的module mod_xsendfile, 让Apache直接发送这个文件给用户:

<?php
    $file = "/tmp/中文名.tar.gz";
 
    $filename = basename($file);
 
    header("Content-type: application/octet-stream");
 
    //处理中文文件名
    $ua = $_SERVER["HTTP_USER_AGENT"];
    $encoded_filename = rawurlencode($filename);
    if (preg_match("/MSIE/", $ua)) {
     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 . ‘"‘);
    }
 
    //让Xsendfile发送文件
    header("X-Sendfile: $file");

  

让PHP更快的提供文件下载

标签:

原文地址:http://www.cnblogs.com/imoxie/p/4595646.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!