March 17, 2011
Another piece of code for PHP developers, useful in open source applications development.
Following is the function for application that needs functionality of resumable download.
public static function dl_file_resumable($file, $is_resume=TRUE)
//First, see if the file exists
die(“404 File not found!“);
//Gather relevent info about file
$size = filesize($file);
$fileinfo = pathinfo($file);
//workaround for IE filename bug with multiple periods / multiple dots in filename
//that adds square brackets to filename – eg. setup.abc.exe becomes setup.abc.exe
$filename = (strstr($_SERVER[‘HTTP_USER_AGENT’], ‘MSIE’)) ?
preg_replace(‘/\./’, ‘%2e’, $fileinfo[‘basename’], substr_count($fileinfo[‘basename’], ‘.’) – 1) :
$file_extension = strtolower($path_info[‘extension’]);
//This will set the Content-Type to the appropriate setting for the file
case ‘zip’: $ctype=’application/zip’; break;
//check if http_range is sent by browser (or download manager)
if($is_resume && isset($_SERVER[‘HTTP_RANGE’]))
list($size_unit, $range_orig) = explode(‘=’, $_SERVER[‘HTTP_RANGE’], 2);
if ($size_unit == ‘bytes’)
//multiple ranges could be specified at the same time, but for simplicity only serve the first range
list($range_from, $extra_ranges) = explode(‘,’, $range_orig, 2);
$range_from = ”;
$range_from = ”;
//figure out download piece from range (if set)
list($seek_start, $seek_end) = explode(‘-‘, $range_from, 2);
//set start and end based on range (if set), else set defaults
//also check for invalid ranges.
$seek_end = (empty($seek_end)) ? ($size – 1) : min(abs(intval($seek_end)),($size – 1));
$seek_start = (empty($seek_start) || $seek_end 0 || $seek_end < ($size – 1))
header(‘HTTP/1.1 206 Partial Content’);
header(‘Content-Range: bytes ‘.$seek_start.’-‘.$seek_end.’/’.$size);
//headers for IE Bugs (is this necessary?)
//header(“Cache-Control: cache, must-revalidate”);
header(‘Content-Type: ‘ . $ctype);
header(‘Content-Disposition: attachment; filename=”‘ . $filename . ‘”‘);
header(‘Content-Length: ‘.($seek_end – $seek_start + 1));
//open the file
$fp = fopen($file, ‘rb’);
//seek to start of missing part
//start buffered download
//reset time limit for big files
inch you’ll find it reestablish to mind in regards to the time I ran into my husband.
I must appreciate this tries you get in establishing the next few paragraphs. I will be believing identical best work within you when you need it in addition
Hello dude! Dominatrix are my passion, please write way more i will arrive back daily to be sure of you !
In the event you overpay ones taxes over the years, you’ll certainly be presenting the costa rica government a no cost personal loan.
There are certainly plenty of particulars like that to take into consideration. That could be a great level to convey up. I offer the thoughts above as normal inspiration however clearly there are questions just like the one you deliver up the place the most important factor shall be working in sincere good faith. I don?t know if greatest practices have emerged round things like that, but I am sure that your job is clearly recognized as a good game. Each boys and girls feel the impression of just a second’s pleasure, for the remainder of their lives.