dongxing6802 2012-06-04 20:06
浏览 35
已采纳

too long

I am trying to deny access to a folder on my server, in which there are files that can only be downloaded via a php script. The php script is used to force the download of files, just like that:

  function downloadFile($file){
        $file_name = $file;
        $mime = 'application/force-download';
        header('Pragma: public');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Cache-Control: private',false);
        header('Content-Type: '.$mime);
        header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
        header('Content-Transfer-Encoding: binary');
        header('Content-Length: '.filesize($file_name));    // provide file size
        header('Connection: close');
        readfile($file_name);
        exit();
    }

And the htaccess must provide access only to localhost:

order deny,allow
deny from all
allow from 127.0.0.1

But every time the script download a zero bytes files with the same name, instead of the complete file. When I delete htaccess, however, everything is fine.. I can't figure out where is the error. Thanks for your help

  • 写回答

1条回答 默认 最新

  • doubi8512 2012-06-04 22:07
    关注

    The problem was that readfile(); need the absolute path of the file on the machine rather than a url.

    e.g. /home/person/file.exe

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大