一.php超大文件下载源代码demo
<?php
set_time_limit(0);
$file = 'test.rar';
if (file_exists($file) && is_file($file)) {
$filesize = filesize($file);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . $filesize);
header('Content-Disposition: attachment; filename=' . $file_name);
$fp = fopen($file, 'rb');
fseek($fp, 0);
ob_start();
while (!feof($fp)) {
$chunk_size = 1024 * 1024 * 2;
echo fread($fp, $chunk_size);
ob_flush();
flush();
sleep(1);
}
ob_end_clean();
fclose($fp);
} else {
echo 'file not exists or has been removed!';
}
exit();
二.测试效果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/549a62e19191d023cb98dab2ad0d5efe.png)
三.参考文章
https://www.liangzl.com/get-article-detail-30838.html