function Download ($sourceFile, $outFile = ') {//begin Writing headers header ("Cache-control:") ; Header ("Cache-control:public"); Set the Output browser format header ("Content-type:application/force-download"); Header ("content-disposition:attachment; Filename= ". $outFile); Header ("Accept-ranges:bytes"); Header ("Content-type:application/force-download"); Header ("Cache-control:"); Header ("Cache-control:public"); Header ("content-disposition:attachment; Filename= ". $outFile); Header ("Accept-ranges:bytes"); $size = FileSize ($sourceFile); If there is a $_server[' http_range '] parameter $httprange = $_server[' Http_range '); The value bytes=4390912-list ($a, $range) = Explode ("$httprange) {//breakpoint after connecting $_server[' Http_range '] = ", $_server[' Http_range ']); If yes, download missing part $size 2 = $size; Total Files bytes $new _length = $size 2-$range; Gets the length of the next download header ("http/1.1 206 Partial Content"); Header ("Content-length: $new _length"); Enter the total length header ("Content-range:bytes {$range}-{$size 2}/{$size}"); Content-range:bytes 4908618-4988927/4988928 95%} else {//first connection $size 2 = $size-1; Header ("Content-range:bytes 0-{$size 2}/{$size}"); Content-range:bytes 0-4988927/4988928 Header ("Content-length:". $size); Output total length}//Open File $fp = fopen ("{$sourceFile}", "RB"); Set pointer position fseek ($FP, $range); Unreal output Ob_clean (); while (!feof ($fp)) {//Set file Maximum execution time set_time_limit (0); Print (Fread ($FP, 1024 * 1)); Output file flush (); Output buffer Ob_flush (); } fclose ($FP); return true; }
HTTP Shard Download File code