Home >Backend Development >PHP Tutorial >PHP breakpoint resume download sample code

PHP breakpoint resume download sample code

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:54:341000browse
  1. $fname = './test.mp3';
  2. $fp = fopen($fname,'rb');
  3. $fsize = filesize($fname);
  4. if (isset( $_server['http_range']) && ($_server['http_range'] != "") && preg_match("/^bytes=([0-9]+)-$/i", $_server['http_range' ], $match) && ($match[1] < $fsize)) { $start = $match[1]; } else { $start = 0; } @header("cache-control: public"); @ header("pragma: public"); if ($star--> 0) {
  5. fseek($fp, $start);
  6. header("http/1.1 206 partial content");
  7. header("content-length : " . ($fsize - $start));
  8. header("content-ranges: bytes" . $start . "-" . ($fsize - 1) . "/" . $fsize);
  9. } else {
  10. header("content-length: $fsize");
  11. header("accept-ranges: bytes");
  12. }
  13. @header("content-type: application/octet-stream");
  14. @header("content- disposition: attachment;filename=mmdld.mp3");
  15. fpassthru($fp);
  16. fpassthru();//The function outputs all remaining data at the file pointer.
Copy code

Instructions: This function reads the given file pointer from the current position to eof and writes the result to the output buffer to implement file downloading.



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