<?php

$file = '文件路径和名字';
 
if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}

?>

 如果文件较

$handle = fopen($file, 'rb'); 
 while(!feof($handle))

{
      echo fread($handle, 1024);
}
    fclose($handle);

 

输出类似于

html代码

<a href="api/image.php?action=down&id=1111" class="btnDownload" target="_blank">下载</a>

 

php用@ readfile() 形式下载文件

 

相关文章:

  • 2022-12-23
  • 2021-05-21
  • 2021-10-25
  • 2021-08-28
  • 2022-02-23
  • 2022-02-18
  • 2021-08-27
猜你喜欢
  • 2021-06-09
  • 2021-10-30
  • 2021-08-18
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案