PHP实现HTTP断点续传的方法

(编辑:jimmy 日期: 2024/9/30 浏览:2)

本文实例讲述了PHP实现HTTP断点续传的方法。分享给大家供大家参考。具体实现方法如下:

<"Cache-control: public");
  header("Pragma: public");
  //解决在IE中下载时中文乱码问题
  $ua = $_SERVER['HTTP_USER_AGENT'];
  if(preg_match('/MSIE/',$ua)) {
    $ie_filename = str_replace('+','%20',urlencode($file));
    header('Content-Dispositon:attachment; filename='.$ie_filename);
  } else {
    header('Content-Dispositon:attachment; filename='.$file);
  }
  $fp = fopen($real,'rb+');
  fseek($fp,$range);
  while(!feof($fp)) {
    set_time_limit(0);
    print(fread($fp,1024));
    flush();
    ob_flush();
  }
  fclose($fp);
}

希望本文所述对大家的php程序设计有所帮助。