PHP 下载文件示例

function download($filePath, $outputName)
{
  ob_end_clean();
  
  $handle = fopen($filePath, "rb");
  header("Content-type: application/octet-stream;charset=utf-8");
  header("Content-Transfer-Encoding: binary");
  header("Accept-Ranges: bytes");
  header("Content-Length: " . filesize($filePath));
  header("Content-Disposition: attachment; filename=\"$outputName\"");

  while (!feof($handle)) {
    echo fread($handle, 10240);
  }

  fclose($handle);
}
文档信息
发表日期:2020-02-21