您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php 断点续传功能_PHP教程

2025/12/8 20:25:32发布8次查看
断点续传指的是在上传时,将上传任务(一个文件或一个压缩包)人为的划分为几个部分,每一个部分采用一个线程进行上传,下面我们来看看php 断点续传功能的实现方法吧。
断点续传指的是在上传时,将上传任务(一个文件或一个压缩包)人为的划分为几个部分,每一个部分采用一个线程进行上传,下面我们来看看php 断点续传功能的实现方法吧。
down('e:/iso/ms.office2003sp1.chs.iso');
    **/
class sd_download {
/**
         * 下载的开始点
         *
         * @access private
         * @var integer
         */
     private $mdownstart;
/**
         * 文件大小
         *
         * @access private
         * @var integer
         */
     private $mfilesize;
/**
         * 文件句柄
         *
         * @access private
         * @var integer
         */
     private $mfilehandle;
/**
         * 文件全路径
         *
         * @access private
         * @var string
         */
     private $mfilepath;
/**
         * 文件下载时显示的文件名
         *
         * @access private
         * @var string
         */
     private $mfilename;
/**
         * 构造函数
         *
         * @access public
         * @return void
         **/
     public function __construct() {
     }
/**
         * 下载
         *
         * @param string $pfilepath 文件全路径
         * @param string pfilename 文件下载时显示的文件名,缺省为实际文件名
         * @access public
         * @return void
         **/
     public function down($pfilepath, $pfilename = '') {
          $this->mfilepath = $pfilepath;
          if(!$this->inifile()) $this->senderror();
          $this->mfilename = empty($pfilename) ? $this->getfilename() : $pfilename;
$this->inifile();
          $this->setstart();
          $this->setheader();
$this->send();
     }
/**
         * 初始化文件信息
         *
         * @access private
         * @return boolean
         **/
     private function inifile() {
          if(!is_file($this->mfilepath)) return false;
          $this->mfilehandle = fopen($this->mfilepath, 'rb');
          $this->mfilesize = filesize($this->mfilepath);
          return true;
     }
/**
         * 设置下载开始点
         *
         * @access private
         * @return void
         **/
     private function setstart() {
          if (!empty($_server['http_range']) && preg_match(/^bytes=([d]?)-([d]?)$/i, $_server['http_range'], $match)) {
               if(empty($match[1])) $this->mdownstart = $match[1];
               fseek($this->mfilehandle, $this->mdownstart);
          }
          else {
               $this->mdownstart = 0;
          }
     }
/**
         * 设置http头
         *
         * @access private
         * @return void
         **/
     private function setheader() {
          @header(cache-control: public);
          @header(pragma: public);
          header(content-length: . ($this->mfilesize - $this->mdownstart));
          if ($this->mdownstart > 0) {
               @header(http/1.1 206 partial content);
               header(content-ranges: bytes . $this->mdownstart . - . ($this->mfilesize - 1) . / . $this->mfilesize);
          }
          else {
               header(accept-ranges: bytes);
          }
          @header(content-type: application/octet-stream);
          @header(content-disposition: attachment;filename= . $this->mfilename);
     }
/**
         * 获取全路径里的文件名部分
         *
         * @access private
         * @return string
         **/
     private function getfilename() {
          return basename ($this->mfilepath);
     }
/**
         * 发送数据
         *
         * @access private
         * @return void
         **/
     private function send() {
          fpassthru($this->mfilehandle);
     }
/**
         * 发送错误
         *
         * @access public
         * @return void
         **/
     public function senderror() {
          @header(http/1.0 404 not found);
          @header(status: 404 not found);
          exit();
     }
}
?>
http://www.bkjia.com/phpjc/630477.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/630477.htmltecharticle断点续传指的是在上传时,将上传任务(一个文件或一个压缩包)人为的划分为几个部分,每一个部分采用一个线程进行上传,下面我们来...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product