PHP File Download:
0){
$seek_start = intval($range[0]);
}
if($range[1] > 0){
$seek_end = intval($range[1]);
}
// Seek to the requested position in the file
fseek($fp, $seek_start);
// Set the range response headers
header(‘HTTP/1.1 206 Partial Content’);
header(‘Content-Length: ‘ . ($seek_end – $seek_start + 1));
header(sprintf(‘Content-Range: bytes %d-%d/%d’, $seek_start, $seek_end, $size));
}
else
{
// Set default response headers
header(‘Content-Length: ‘ . $size);
}
// Set up the size of each piece of data we send
$block_size = 1024;
if($rate > 0)
{
// Multiply by rate if specified
$block_size *= $rate;
}
// Prevent the script from timing out
set_time_limit(0);
// Start sending the file
while(!feof($fp))
{
// Output data
print(fread($fp, $block_size));
flush();
if($rate > 0)
{
// Wait one second before next block if rate is specified
sleep(1);
}
}
// Close the file
fclose($fp);
}
?>
No comments:
Post a Comment