Home  >  Article  >  Backend Development  >  PHP breakpoint resume download function_PHP tutorial

PHP breakpoint resume download function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:07:08926browse

Let’s take a look at using PHP to resume the upload. This function is a great time saver

Let’s take a look at using PHP to resume the upload. This function is a great time saver

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

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

$size=filesize($file);
$size1=$size-1;
//Get byte range
if(isset($_SERVER['HTTP_RANGE'])) {
List($name, $range) = explode("=",$_SERVER['HTTP_RANGE']);
$length=$size1-$range;
header("HTTP/1.1 206 Partial Content"); //http protocol header status code, indicating partial content transmission
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");

//Set the file pointer position
fseek($fp,$range);

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630476.htmlTechArticleLet’s take a look at using PHP to resume the upload. This function saves time very well. Let’s take a look at how to use it. PHP resume uploading from a breakpoint. This function saves time?php header(Cache-Control: public...
Statement:
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