php无法下载大文件的解决办法:首先找到并打开“php.ini”文件;然后将“memory_limit”设置为1024M;接着将数据输出到客户端浏览器中即可。
推荐:《PHP视频教程》y p c : E R - s
解决使用% X e } {Pg 5 RHP无法下载大文件的问题
在实际应用中,使用PHP的fread()函数读取服务器文件会有大小限制。当服务器文件大小超过Z R R F A Q一定量时(9 P @ Z m O - u128M?),客户端浏览器无法下载文件。是因为配置文件php.ini里的memory_limit的限制吗?
将memory_limit设置为1024W ] [M后,测. r ? 8 ` $ h Z [试一个180M的文件,发现问题依旧,代码:
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);
上面的读取方式是一次性将数据输出到客户端浏览器中,难道跟这有关系?试着从文件中一行一行读取:y E 3 !
headP s { 3 = [er('content-type:application/octet-stream');
header('accept-ranges: bytes');
header('content-length: '.filesize($filePath));
header('content-dispos: H U n r x M Yition:attachment;filename='.$fileName);
$fp = fop0 E ren($filePath, "r");
while(!feof($fp)) {
echo fgets($fp, 4096);
}
fclose($fp)N 8 H d t 2 H;
啊哈!没有问题了。
以上就是php无法下载大* * d % q E :文件怎么办的详细内容。