$user_file=ROOT_PATH."好东西.rar";
header("Content-Type: application/force-download"); 
            header("Content-Disposition: attachment; filename=".basename($user_file)); 
            readfile($user_file); 
其中ROOT_PATH为你自定义的路径

解决方案 »

  1.   


    function downloads($name){
                $file = fopen($name,"r");
                Header("Content-type: application/octet-stream");
                Header("Accept-Ranges: bytes");
                Header("Accept-Length: ".filesize($name));
                Header("Content-Disposition: attachment; filename=".$name);
                fclose($file);
    }
    downloads('test.txt');
      

  2.   

    可以参考这个http://blog.csdn.net/u011619326/article/details/37651635。
      

  3.   


    function downloads($name){
                $file = fopen($name,"r");
                Header("Content-type: application/octet-stream");
                Header("Accept-Ranges: bytes");
                Header("Accept-Length: ".filesize($name));
                Header("Content-Disposition: attachment; filename=".$name);
                fclose($file);
    }
    downloads('好东西.rar');
      

  4.   

    header("content-type: text/html;charset=utf-8");$file_name="好.rar";
    $filedown=new DownFile();
    $filedown->down_file($file_name,"/");class DownFile{
    //$file_sub_dir 有目录格式:/xxx/,没有目录格式:/
    function down_file($file_name,$file_sub_dir){
    $file_name=iconv("utf-8","gb2312",$file_name);
    $file_path=$_SERVER['DOCUMENT_ROOT'].$file_sub_dir.$file_name;
    if(!file_exists($file_path)){
    echo $file_path." 文件不存在!";
    return;
    }
    $fp=fopen($file_path,"r");
    $file_size=filesize($file_path); if($file_size>1*1024*1024){//自己调
    echo "<script>alert('你下载的文件过大!');</script>";
    return;
    } header("Content-type:application/octet-stream");
    header("Accept-Ranges:bytes");
    header("Accept-Length:$file_size");
    header("Content-Disposition:attachment;filename=".$file_name);

    $buffer=1024;
    $file_count=0;
    while(!feof($fp) && ($file_size-$file_count>0)){
    $file_data=fread($fp,$buffer);
    $file_count+=$buffer;
    echo $file_data;
    }
    fclose($fp);
    }
    }
      

  5.   


    我测试了一下,下载确实是下载了一个rar的文件,但是是一秒钟下完,打开却打不开,是不是有点问题哦
      

  6.   


    我测试了一下,下载确实是下载了一个rar的文件,但是是一秒钟下完,打开却打不开,是不是有点问题哦不好意思,我也没有测试。还是用楼上那位的代码吧
      

  7.   

    我测试没有该问题
    请将你的php文件编码改为utf-8后再试一下
      

  8.   


    是utf-8编码的,真的是出现 ע���뼰����˵����.rar文件不存在
      

  9.   

    不好意思,utf-8下请将此句:$file_name=iconv("utf-8","gb2312",$file_name);去掉试试