Home > php教程 > php手册 > php 断点续传下载功能

php 断点续传下载功能

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:09:51
Original
1208 people have browsed it

我们来看看用php 断点续传吧,这个功能很好的节省时间

 

我们来看看用php 断点续传吧,这个功能很好的节省时间

header("Cache-Control: public");
header("Accept-Ranges: bytes");

$file = "a.rar";
$filename = "a.rar";

$size=filesize($file);
$size1=$size-1;
//获得字节范围
if(isset($_SERVER['HTTP_RANGE'])) {
   list($name, $range) = explode("=",$_SERVER['HTTP_RANGE']);
   $length=$size1-$range;
   header("HTTP/1.1 206 Partial Content");  //http协议头状态码,表示以部分内容传输
   header("Content-Range: bytes ".$range."-".$size1."/".$size);
}else{
   $length = $size;
}

header("Content-Length: $length");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$filename);

$fp=fopen($file,"rb");

//设定文件指针位置
fseek($fp,$range);

while(!feof($fp)){
   set_time_limit(0);
   echo fread($fp,1024);
   flush();
   ob_flush();
}
fclose($fp);
exit;
?>

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template