404 File not found!"); } //Gather relevent info about file $filename = basename($file); $file_extension = strtolower(substr(strrchr($filename,"."),1)); // This will set the Content-Type to the appropriate setting for the file switch( $file_extension ) { case "exe": $ctype="application/octet-stream"; break; case "sit": $ctype="application/x-sit"; break; case "pdf": $ctype="application/pdf"; break; case "dmg": $ctype="application/x-apple-diskimage"; break; case "zip": $ctype="application/zip"; break; case "mp3": $ctype="audio/mpeg"; break; case "mpg": $ctype="video/mpeg"; break; case "mov": $ctype="video/quicktime"; break; case "avi": $ctype="video/x-msvideo"; break; // The following are for extensions that shouldn't be downloaded // (sensitive stuff, like php files) case "php": case "htm": case "html": case "txt": die("Cannot be used for ". $file_extension ." files!"); break; default: $ctype="application/force-download"; } // Begin writing headers header("Cache-Control:"); header("Cache-Control: public"); header("Content-Type: $ctype"); $filespaces = str_replace("_", " ", $filename); // if your filename contains underscores, replace them with spaces $header='Content-Disposition: attachment; filename='.$filespaces; header($header); header("Accept-Ranges: bytes"); $size = filesize($file); $speed = intval($size/$time); if (!$speed) $speed = 1; // check if http_range is sent by browser (or download manager) if(isset($_SERVER['HTTP_RANGE'])) { // if yes, download missing part $seek_range = substr($_SERVER['HTTP_RANGE'] , 6); $range = explode( '-', $seek_range); if($range[0] > 0) { $seek_start = intval($range[0]); } if($range[1] > 0) { $seek_end = intval($range[1]); } header("HTTP/1.1 206 Partial Content"); header("Content-Length: " . ($seek_end - $seek_start + 1)); header("Content-Range: bytes $seek_start-$seek_end/$size"); } else { header("Content-Range: bytes 0-$seek_end/$size"); header("Content-Length: $size"); } //open the file $fp = fopen("$file","rb"); //seek to start of missing part fseek($fp,$seek_start); //start buffered download while(!feof($fp)) { //reset time limit for big files set_time_limit(0); #if ($init) { print(fread($fp,$speed)); #1024* flush(); sleep(1); # } # else { # print(fread($fp,10000)); #1024* # flush(); # sleep(1); # $init = 1; # } } fclose($fp); exit; } ?>