我希望PHP代码下载大小超过+ 5GB且 可恢复
的文件我在这里和其他网站上看到多个代码,但所有这些代码下载最多2 GB并停止或无法恢复!
此代码之一的示例: 我有文件(4 GB)它只下载的脚本(2 GB)并停止或下载4 GB但可以'恢复它!
最后:我在下面使用这个代码可以下载大文件,但在2GB之后无法恢复,在那里又回到了第一个-_-
function smartReadFile($location, $filename)
{ if(!file_exists($location))
{ header ("HTTP/1.0 404 Not Found");
return;
}
$size=filesize64($location);
$time=date('r',filemtime($location));
$fm=@fopen($location,'rb');
if(!$fm)
{ header ("HTTP/1.0 505 Internal server error");
return;
}
$begin=0;
$end=$size;
if(isset($_SERVER['HTTP_RANGE']))
{ if(preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches))
{ $begin = floatval($matches[1]) ;
if( !empty($matches[2]) ) {
$end = floatval($matches[1]);
}
}
}
if($begin>0||$end<$size)
header('HTTP/1.0 206 Partial Content');
else
header('HTTP/1.0 200 OK');
$get_type= mime_content_type($location);
$path_parts = pathinfo($location);
$file_ext = $path_parts['extension'];
$ctype_default = "application/force-download";
$content_types = array(
"exe" => "application/octet-stream",
"zip" => "application/zip",
"rar" => "application/x-rar",
"avi" => "video/x-msvideo",
"apk" => "application/vnd.android.package-archive",
"text" => "text/plain",
"mp4" => "video/mp4",
"mp3" => "video/mp3",
);
$ctype = isset($content_types[$file_ext]) ? $content_types[$file_ext] : $ctype_default;
header("Content-Type: " . $ctype);
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('Accept-Ranges: bytes');
header('Content-Length:'.($end-$begin));
header("Content-Range: bytes $begin-$end/$size");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Transfer-Encoding: binary\n");
header("Last-Modified: $time");
header('Connection: close');
$cur=$begin;
fseek($fm,$begin,0);
while(!feof($fm)&&$cur<$end&&(connection_status()==0))
{ print fread($fm,min(10240*16,$end-$cur));
$cur+=10240*16;
}
}
此代码可以下载任意大小的文件并恢复它,但是当你停止它并恢复它时访问2GB会让你回到第一个
请解决我的问题或给我代码支持下载大文件+ 5GB和可恢复
我使用Wamp Server,Windows Server 2012 x64
感谢