【问题标题】:php download limit zip damage when set file size设置文件大小时php下载限制zip损坏
【发布时间】:2018-12-23 17:02:28
【问题描述】:

设置文件大小标题后压缩损坏

我有这个代码来限制 php 的下载速度:

function readfile_chunked($filename, $retbytes = TRUE) {
 $download_rate = 85;  global $filename ;
  // send headers
  header('Cache-control: private');
  header('Content-Type: application/octet-stream');
  header('Content-Length: '.filesize($filename));
  header('Content-Disposition: filename=file.zip');

  // flush content
  flush();
  // open file stream
  $file = fopen($filename, "r");
  while(!feof($file)) {

      // send the current file part to the browser
      print fread($file, round($download_rate * 1024));

      // flush the content to the browser
      flush();

      // sleep one second
      usleep(200);
  }

}

当我像这样设置内容长度的标题时:

header('Content-Length: '.filesize($filename));

并打开下载的文件向我显示文件已损坏的警报。不仅仅是我在 jpg 文件上尝试的 zip 文件,而且它是相同的。

但是当我删除文件大小标题时,文件或图像打开时没有任何错误

【问题讨论】:

    标签: php download http-headers zip zipfile


    【解决方案1】:

    我通过在函数开头添加 ob_clean() 解决了这个问题。我试图解决它 3 个月这需要一个聚会;)

    function party(forVisitors){
    Drink(); 
    Play();
    HaveFun(); 
    GoHome();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-29
      • 2018-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-09
      相关资源
      最近更新 更多