Example of php supporting multi-threaded downloading
Release: 2016-07-25 09:10:27
Original
889 people have browsed it
header("Cache-Control: public");
- header("Accept-Ranges: bytes");
$file = "a.7z";
- $filename = "a.7z";
$size=filesize($file);
- $size1=$size-1;
- //Get the word Section 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");< ;/p>
//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;
- ?>
Copy code
|
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 Articles by Author
-
2024-08-20 08:31:32
-
2024-08-20 07:34:02
-
2024-08-20 07:33:36
-
2024-08-20 07:32:07
-
2024-08-20 07:32:02
-
2024-08-20 07:07:02
-
2024-08-20 07:04:05
-
2024-08-20 07:01:02
-
2024-08-20 06:55:40
-
2024-08-20 06:55:02