-
- $fname = './test.mp3';
- $fp = fopen($fname,'rb');
- $fsize = filesize($fname);
- 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) {
- fseek($fp, $start);
- header("http/1.1 206 partial content");
- header("content-length : " . ($fsize - $start));
- header("content-ranges: bytes" . $start . "-" . ($fsize - 1) . "/" . $fsize);
- } else {
- header("content-length: $fsize");
- header("accept-ranges: bytes");
- }
- @header("content-type: application/octet-stream");
- @header("content- disposition: attachment;filename=mmdld.mp3");
- fpassthru($fp);
- 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.
|