我正在使用php下载文件,而不是在新窗口中打开文件本身。对于较小的文件似乎可以正常工作,但对于较大的文件则无法工作(我需要在大型文件上使用)。这是我必须下载文件的代码:
function downloadFile($file) {
if (file_exists($file)) {
//download 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, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: '.filesize($file));
ob_clean();
flush();
readfile($file);
exit;
};
};
但是,当我尝试下载大文件(例如265mb)时,浏览器告诉我找不到文件吗?文件一定在服务器上,脚本对于较小的文件也可以正常工作。有什么方法可以下载类似于我已有的大文件?