Exemplo n.º 1
0
 /**
  * Upload a file to the current upload token
  * @param file $fileData
  * @param bool $resume
  * @param bool $finalChunk
  * @param int $resumeAt
  */
 public function uploadFileToToken($fileData, $resume = false, $finalChunk = true, $resumeAt = -1)
 {
     $allowedStatuses = array(UploadToken::UPLOAD_TOKEN_PENDING, UploadToken::UPLOAD_TOKEN_PARTIAL_UPLOAD);
     if (!in_array($this->_uploadToken->getStatus(), $allowedStatuses, true)) {
         throw new kUploadTokenException("Invalid upload token status", kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS);
     }
     $this->updateFileName($fileData);
     try {
         $this->checkIfFileIsValid($fileData);
     } catch (kUploadTokenException $ex) {
         if (!$resume && $finalChunk) {
             kFlowHelper::handleUploadFailed($this->_uploadToken);
         }
         $this->tryMoveToErrors($fileData);
         throw $ex;
     }
     if ($resume) {
         $this->handleResume($fileData, $resumeAt);
     } else {
         $this->handleMoveFile($fileData);
     }
     $fileSize = kFile::fileSize($this->_uploadToken->getUploadTempPath());
     if ($finalChunk) {
         $this->_uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_FULL_UPLOAD);
     } else {
         $this->_uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_PARTIAL_UPLOAD);
     }
     $this->_uploadToken->setUploadedFileSize($fileSize);
     $this->_uploadToken->setDc(kDataCenterMgr::getCurrentDcId());
     $this->_uploadToken->save();
     $this->addTrackEntry();
 }