$file="iproom/weboffice_mpc.jnj"; // 要下載的路徑
$fsize = filesize($file);
$fname = basename($file);
$ftime = filemtime($file);
$range = $_SERVER['HTTP_RANGE'];
$r_start = 0;
$c_length = $fsize;
if($range) {
$reg = "/bytes=([0-9]+)-([0-9]*)/";
preg_match($reg, $range, $matches);
$r_start = (int) $matches[1];
$r_stop = (int) $matches[2];
if ($r_stop < $r_start) $r_stop = $fsize - 1;
$c_length = $r_stop - $r_start + 1;
header('HTTP/1.1 206 Partial Content');
header('Content-Range: bytes '.
$r_start . '-' . $r_stop . '/' . $fsize);
} else {
header('HTTP/1.1 200 OK');
}
header('Last-Modified: '.gmstrftime('%a, %d %b %Y %T', $ftime).' GMT');
header('Content-Disposition: attachment; filename="'.$fname.'"');
header('Accept-Ranges: bytes');
header('Content-Type: application/x-unknown');
header('content-Transfer-Encoding: binary');
header('Content-Length: '.$c_length);
if ($fp = fopen($file, 'rb')) {
fseek($fp, $r_start);
for($len = $c_length; $len > 0;) {
$rlen = $len < 128000? $len : 128000;
echo(fread($fp, $rlen));
$len = $len - $rlen;
set_time_limit(20);
}
fclose($fp);
}
clearstatcache();
exit;
留言列表