我有一段代码在许多服务器上表现良好。
它用于通过readfile php函数下载文件。
但是,在特定的一个服务器上,对于大于25MB的文件无法正常工作。
以下是代码:
$sysfile = '/var/www/html/myfile';
if(file_exists($sysfile)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="mytitle"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($sysfile));
ob_clean();
flush();
readfile($sysfile);
exit();
当我尝试下载小于25MB的文件时没有问题,但当文件更大时,下载的文件大小为0字节。
我尝试使用read()和file_get_contents函数,但问题仍然存在。
我的php版本是5.5.3,内存限制设置为80MB。错误报告已开启,但即使在日志文件中也没有显示任何错误。