• <bdo id='ajjQx'></bdo><ul id='ajjQx'></ul>
    <i id='ajjQx'><tr id='ajjQx'><dt id='ajjQx'><q id='ajjQx'><span id='ajjQx'><b id='ajjQx'><form id='ajjQx'><ins id='ajjQx'></ins><ul id='ajjQx'></ul><sub id='ajjQx'></sub></form><legend id='ajjQx'></legend><bdo id='ajjQx'><pre id='ajjQx'><center id='ajjQx'></center></pre></bdo></b><th id='ajjQx'></th></span></q></dt></tr></i><div id='ajjQx'><tfoot id='ajjQx'></tfoot><dl id='ajjQx'><fieldset id='ajjQx'></fieldset></dl></div>
    <legend id='ajjQx'><style id='ajjQx'><dir id='ajjQx'><q id='ajjQx'></q></dir></style></legend>

    1. <small id='ajjQx'></small><noframes id='ajjQx'>

      1. <tfoot id='ajjQx'></tfoot>

        支持简历的 PHP 远程文件流传输

        PHP Remote file streaming with Resume Support(支持简历的 PHP 远程文件流传输)

        <legend id='tl23t'><style id='tl23t'><dir id='tl23t'><q id='tl23t'></q></dir></style></legend>

        1. <i id='tl23t'><tr id='tl23t'><dt id='tl23t'><q id='tl23t'><span id='tl23t'><b id='tl23t'><form id='tl23t'><ins id='tl23t'></ins><ul id='tl23t'></ul><sub id='tl23t'></sub></form><legend id='tl23t'></legend><bdo id='tl23t'><pre id='tl23t'><center id='tl23t'></center></pre></bdo></b><th id='tl23t'></th></span></q></dt></tr></i><div id='tl23t'><tfoot id='tl23t'></tfoot><dl id='tl23t'><fieldset id='tl23t'></fieldset></dl></div>
            <tbody id='tl23t'></tbody>
        2. <small id='tl23t'></small><noframes id='tl23t'>

            <bdo id='tl23t'></bdo><ul id='tl23t'></ul>
            <tfoot id='tl23t'></tfoot>

                • 本文介绍了支持简历的 PHP 远程文件流传输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  首先,我知道之前有人问过类似的问题.

                  Firstly, I am aware of similar question being asked before.

                  这个主题几乎解释了这个问题,但仍然,

                  The subject pretty much explains the question but still,

                  文件托管在另一台服务器上,用户将通过我的脚本下载文件,流式传输给他...

                  the file is hosted on another server, the user will download file via my script, streamed to him...

                  但问题是用户一旦暂停就无法恢复...有什么解决办法吗?

                  But the problem is user can't resume it once paused...any solutions?

                  推荐答案

                  您可以尝试使用 Accept-RangesContent-Range 实现自己的下载脚本,这里是一个概念教授:

                  You can try implementing your own download script using Accept-Ranges and Content-Range here is a prof of concept :

                  set_time_limit(0);
                  $download = new ResumeDownload("word.dir.txt", 50000); //delay about in microsecs 
                  $download->process();
                  

                  使用 Internet 下载管理器

                  开始

                  暂停

                  暂停状态

                  简历

                  完成

                  使用的类

                  class ResumeDownload {
                      private $file;
                      private $name;
                      private $boundary;
                      private $delay = 0;
                      private $size = 0;
                  
                      function __construct($file, $delay = 0) {
                          if (! is_file($file)) {
                              header("HTTP/1.1 400 Invalid Request");
                              die("<h3>File Not Found</h3>");
                          }
                  
                          $this->size = filesize($file);
                          $this->file = fopen($file, "r");
                          $this->boundary = md5($file);
                          $this->delay = $delay;
                          $this->name = basename($file);
                      }
                  
                      public function process() {
                          $ranges = NULL;
                          $t = 0;
                          if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_SERVER['HTTP_RANGE']) && $range = stristr(trim($_SERVER['HTTP_RANGE']), 'bytes=')) {
                              $range = substr($range, 6);
                              $ranges = explode(',', $range);
                              $t = count($ranges);
                          }
                  
                          header("Accept-Ranges: bytes");
                          header("Content-Type: application/octet-stream");
                          header("Content-Transfer-Encoding: binary");
                          header(sprintf('Content-Disposition: attachment; filename="%s"', $this->name));
                  
                          if ($t > 0) {
                              header("HTTP/1.1 206 Partial content");
                              $t === 1 ? $this->pushSingle($range) : $this->pushMulti($ranges);
                          } else {
                              header("Content-Length: " . $this->size);
                              $this->readFile();
                          }
                  
                          flush();
                      }
                  
                      private function pushSingle($range) {
                          $start = $end = 0;
                          $this->getRange($range, $start, $end);
                          header("Content-Length: " . ($end - $start + 1));
                          header(sprintf("Content-Range: bytes %d-%d/%d", $start, $end, $this->size));
                          fseek($this->file, $start);
                          $this->readBuffer($end - $start + 1);
                          $this->readFile();
                      }
                  
                      private function pushMulti($ranges) {
                          $length = $start = $end = 0;
                          $output = "";
                  
                          $tl = "Content-type: application/octet-stream
                  ";
                          $formatRange = "Content-range: bytes %d-%d/%d
                  
                  ";
                  
                          foreach ( $ranges as $range ) {
                              $this->getRange($range, $start, $end);
                              $length += strlen("
                  --$this->boundary
                  ");
                              $length += strlen($tl);
                              $length += strlen(sprintf($formatRange, $start, $end, $this->size));
                              $length += $end - $start + 1;
                          }
                          $length += strlen("
                  --$this->boundary--
                  ");
                          header("Content-Length: $length");
                          header("Content-Type: multipart/x-byteranges; boundary=$this->boundary");
                          foreach ( $ranges as $range ) {
                              $this->getRange($range, $start, $end);
                              echo "
                  --$this->boundary
                  ";
                              echo $tl;
                              echo sprintf($formatRange, $start, $end, $this->size);
                              fseek($this->file, $start);
                              $this->readBuffer($end - $start + 1);
                          }
                          echo "
                  --$this->boundary--
                  ";
                      }
                  
                      private function getRange($range, &$start, &$end) {
                          list($start, $end) = explode('-', $range);
                  
                          $fileSize = $this->size;
                          if ($start == '') {
                              $tmp = $end;
                              $end = $fileSize - 1;
                              $start = $fileSize - $tmp;
                              if ($start < 0)
                                  $start = 0;
                          } else {
                              if ($end == '' || $end > $fileSize - 1)
                                  $end = $fileSize - 1;
                          }
                  
                          if ($start > $end) {
                              header("Status: 416 Requested range not satisfiable");
                              header("Content-Range: */" . $fileSize);
                              exit();
                          }
                  
                          return array(
                                  $start,
                                  $end
                          );
                      }
                  
                      private function readFile() {
                          while ( ! feof($this->file) ) {
                              echo fgets($this->file);
                              flush();
                              usleep($this->delay);
                          }
                      }
                  
                      private function readBuffer($bytes, $size = 1024) {
                          $bytesLeft = $bytes;
                          while ( $bytesLeft > 0 && ! feof($this->file) ) {
                              $bytesLeft > $size ? $bytesRead = $size : $bytesRead = $bytesLeft;
                              $bytesLeft -= $bytesRead;
                              echo fread($this->file, $bytesRead);
                              flush();
                              usleep($this->delay);
                          }
                      }
                  }
                  

                  使用的文件

                  这篇关于支持简历的 PHP 远程文件流传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <small id='wlYyl'></small><noframes id='wlYyl'>

                        <bdo id='wlYyl'></bdo><ul id='wlYyl'></ul>
                        <i id='wlYyl'><tr id='wlYyl'><dt id='wlYyl'><q id='wlYyl'><span id='wlYyl'><b id='wlYyl'><form id='wlYyl'><ins id='wlYyl'></ins><ul id='wlYyl'></ul><sub id='wlYyl'></sub></form><legend id='wlYyl'></legend><bdo id='wlYyl'><pre id='wlYyl'><center id='wlYyl'></center></pre></bdo></b><th id='wlYyl'></th></span></q></dt></tr></i><div id='wlYyl'><tfoot id='wlYyl'></tfoot><dl id='wlYyl'><fieldset id='wlYyl'></fieldset></dl></div>

                              <tbody id='wlYyl'></tbody>
                            <legend id='wlYyl'><style id='wlYyl'><dir id='wlYyl'><q id='wlYyl'></q></dir></style></legend>
                            <tfoot id='wlYyl'></tfoot>