Example of multi-thread download supported by php
Header ("Cache-Control: public ");
- Header ("Accept-Ranges: bytes ");
$ File = "a.7z ";
- $ Filename = "a.7z ";
$ Size = filesize ($ file );
- $ Size1 = $ size-1;
- // Obtain the byte range
- If (isset ($ _ SERVER ['http _ range']) {
- List ($ name, $ range) = explode ("=", $ _ SERVER ['http _ range']);
- $ Length = $ size1-$ range;
- Header ("HTTP/1.1 206 Partial Content"); // The http header status code, indicating that some Content is transmitted
- Header ("Content-Range: bytes". $ range. "-". $ size1. "/". $ size );
- } Else {
- $ Length = $ size;
- }
Header ("Content-Length: $ length ");
- Header ("Content-Type: application/octet-stream ");
- Header ("Content-Disposition: attachment; filename =". $ filename );
$ Fp = fopen ($ file, "rb ");
// Set the file pointer position
- Fseek ($ fp, $ range );
While (! Feof ($ fp )){
- Set_time_limit (0 );
- Echo fread ($ fp, 1024 );
- Flush ();
- Ob_flush ();
- }
- Fclose ($ fp );
- Exit;
- ?>
|