-
-
$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] 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();//函数输出文件指针处的所有剩余数据。
复制代码
说明:
该函数将给定的文件指针从当前的位置读取到 eof,并把结果写到输出缓冲区,进而实现文件下载。
|