Esempio n. 1
0
 /**
  * Send the next part of the file to upload.
  * @param [$chunk] the next set of bytes to send. If false will used $data passed
  * at construct time.
  */
 public function nextChunk($chunk = false, $prevResumeUri = false, $fileSizeUploaded = 0)
 {
     $this->resumeUri = $prevResumeUri;
     $this->progress = $fileSizeUploaded;
     if (false == $this->resumeUri) {
         $this->resumeUri = $this->getResumeUri();
     }
     if (false == $chunk) {
         $chunk = substr($this->data, $this->progress, $this->chunkSize);
     }
     $lastBytePos = $this->progress + strlen($chunk) - 1;
     $headers = array('content-range' => "bytes {$this->progress}-{$lastBytePos}/{$this->size}", 'content-type' => $this->request->getRequestHeader('content-type'), 'content-length' => $this->chunkSize, 'expect' => '');
     $httpRequest = new IWP_google_Http_Request($this->resumeUri, 'PUT', $headers, $chunk);
     if ($this->client->getClassConfig("IWP_google_Http_Request", "enable_gzip_for_uploads")) {
         $httpRequest->enableGzip();
     } else {
         $httpRequest->disableGzip();
     }
     $response = $this->client->getIo()->makeRequest($httpRequest);
     $response->setExpectedClass($this->request->getExpectedClass());
     $code = $response->getResponseHttpCode();
     $this->httpResultCode = $code;
     if (308 == $code) {
         // Track the amount uploaded.
         $range = explode('-', $response->getResponseHeader('range'));
         $this->progress = $range[1] + 1;
         // Allow for changing upload URLs.
         $location = $response->getResponseHeader('location');
         if ($location) {
             $this->resumeUri = $location;
         }
         // No problems, but upload not complete.
         $status = array();
         $status['resumeURI'] = $this->resumeUri;
         $status['progress'] = $this->progress;
         $status['status'] = false;
         return $status;
     } else {
         $status['progress'] = $this->progress;
         $status['status'] = IWP_google_Http_REST::decodeHttpResponse($response);
         return $status;
         //return IWP_google_Http_REST::decodeHttpResponse($response);
     }
 }