Example of php supporting multi-threaded downloading

WBOY
Release: 2016-07-25 09:10:27
Original
889 people have browsed it
  1. header("Cache-Control: public");

  2. header("Accept-Ranges: bytes");

  3. $file = "a.7z";

  4. $filename = "a.7z";

  5. $size=filesize($file);

  6. $size1=$size-1;
  7. //Get the word Section range
  8. if(isset($_SERVER['HTTP_RANGE'])) {
  9. list($name, $range) = explode("=",$_SERVER['HTTP_RANGE']);
  10. $length=$size1-$ range;
  11. header("HTTP/1.1 206 Partial Content"); //http protocol header status code, indicating partial content transmission
  12. header("Content-Range: bytes ".$range."-".$size1." /".$size);
  13. }else{
  14. $length = $size;
  15. }

  16. header("Content-Length: $length");

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

  19. $fp=fopen($file,"rb");< ;/p>

  20. //Set the file pointer position

  21. fseek($fp,$range);

  22. while(!feof($fp)){

  23. set_time_limit(0 );
  24. echo fread($fp,1024);
  25. flush();
  26. ob_flush();
  27. }
  28. fclose($fp);
  29. exit;
  30. ?>

Copy code


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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!