下载大文件

set_time_limit(0);
$fileSize = filesize($filename);
header('Expires: 0');
header('Pragma: public');
header('Cache-Control:must-revalidate, post-check=0, pre-check=0');
header('Cache-Control:public');
header('Content-Type: application/zip');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename=' . self::getBasename($filename));
header('Content-Length: ' . $fileSize);
$fp = fopen($filename, 'rb');
  if($fp){
      while(!feof($fp)) {
          echo fread($fp, 1024*1024);
          flush(); // this is essential for large downloads
          if (connection_status()!=0) {
              @fclose($fp);
              die();
          }
      }
      @fclose($fp);
  }
unlink($filename);

你可能感兴趣的:(php)