$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;

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 BlackHawk 的頭像
    BlackHawk

    鐵人

    BlackHawk 發表在 痞客邦 留言(0) 人氣()