|
/**
* Breakpoint resume implementation of PHP-HTTP
* @ Param string $ path: path of the file
* @ Param string $ file: file name
* @ Return void
*/
Function download ($ path, $ file ){
$ Real = $ path. '/'. $ file;
If (! File_exists ($ real )){
Return false;
}
$ Size = filesize ($ real );
$ Size2 = $ size-1;
$ Range = 0;
If (isset ($ _ SERVER ['http _ range']) {
Header ('http/1.1 206 Partial content ');
$ Range = str_replace ('=', '-', $ _ SERVER ['http _ range']);
$ Range = explode ('-', $ range );
$ Range = trim ($ range [1]);
Header ('content-Length: '. $ size );
Header ('content-Range: bytes '. $ range.'-'. $ size2.'/'. $ size );
} Else {
Header ('content-Length: '. $ size );
Header ('content-Range: bytes 0-'. $ size2.'/'. $ size );
}
Header ('accenpt-Ranges: bytes ');
Header ('application/octet-stream ');
Header ("Cache-control: public ");
Header ("Pragma: public ");
// Solve Chinese garbled characters during download in IE
$ Ua = $ _ SERVER ['http _ USER_AGENT '];
If (preg_match ('/MSIE/', $ ua )){
$ Ie_filename = str_replace ('+', '% 20', urlencode ($ file ));
Header ('content-Dispositon: attachment; filename = '. $ ie_filename );
} Else {
Header ('content-Dispositon: attachment; filename = '. $ file );
}
$ Fp = fopen ($ real, 'RB + ');
Fseek ($ fp, $ range );
While (! Feof ($ fp )){
Set_time_limit (0 );
Print (fread ($ fp, 1024 ));
Flush ();
Ob_flush ();
}
Fclose ($ fp );
}
/* End of PHP */ |