我正在尝试使用PHP来提供文件下载。我可以让文件开始下载,但它只能下载大约280MB的1GB文件。我在共享主机上,所以这可能是问题,如果这不是我的代码的问题:
function downloadFile($file){
if (file_exists($file)) {
if(is_dir($file)){return false;}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: '.sprintf("%u", filesize($file)));
ob_clean();
$handle = fopen($file, "rb");
$chunksize=(sprintf("%u", (filesize($file))/1024));
set_time_limit(0);
while (!feof($handle)) {
echo fgets($handle, $chunksize);
flush();
}
fclose($handle);
die;
}else{ echo "file not found";}
return;
}