php无法下载大文件的解决办法:首先找到并打开“php.ini”文件;然后将“memory_limit”设置为1024M;接着将数据输出到客户端浏览器中即可。

推荐:《PHP视频教程》
解决使用PHP无法下载大文件的问题
在实际应用中,使用PHP的fread()函数读取服务器文件会有大小限制。当服务器文件大小超过一定量时(128M?),客户端浏览器无法下载文件。是因为配置文件php.ini里的memory_limit的限制吗?
将memory_limit设置为1024M后,测试一个180M的文件,发现问题依旧,代码:
立即学习“PHP免费学习笔记(深入)”;
header('content-type:application/octet-stream');
header('accept-ranges: bytes');
header('content-length: '.filesize($filePath));
header('content-disposition:attachment;filename='.$fileName);
$fp = fopen($filePath, "r");
echo fread($fp, filesize($filePath));
fclose($fp);上面的读取方式是一次性将数据输出到客户端浏览器中,难道跟这有关系?试着从文件中一行一行读取:
header('content-type:application/octet-stream');
header('accept-ranges: bytes');
header('content-length: '.filesize($filePath));
header('content-disposition:attachment;filename='.$fileName);
$fp = fopen($filePath, "r");
while(!feof($fp)) {
echo fgets($fp, 4096);
}
fclose($fp);啊哈!没有问题了。
以上就是php无法下载大文件怎么办的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号