php用@ readfile() 形式下载文件
<?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>