public function processActionUpload(array $params) { $storage = $this->getStorageObject(); if ($this->getDesktopDiskVersion() > 0) { $this->checkRequiredParams($params, array('name')); $filename = $params['name']; } if ($storage::compareVersion($_SERVER['CONTENT_LENGTH'], (string) min(CUtil::unformat(ini_get('upload_max_filesize')), CUtil::unformat(ini_get('post_max_size')))) > 0) { return $this->sendResponse(array('status' => static::STATUS_TOO_BIG)); } if (empty($_FILES['file']) || !is_array($_FILES['file'])) { throw new Exception('Please load file!'); } list($startRange, $endRange, $fileSize) = $this->getContentRange(); if ($startRange !== null) { if ($endRange - $startRange + 1 != $_FILES['file']['size']) { return $this->sendResponse(array('status' => static::STATUS_CHUNK_ERROR, 'message' => 'Size of file: ' . $_FILES['file']['size'] . ' not equals size of chunk: ' . ($endRange - $startRange + 1) . '')); } if ($startRange == 0) { //attempt to decide: cloud? not cloud? $bucket = $this->findBucketForFile(array('name' => $filename, 'fileSize' => $fileSize)); if ($bucket !== false) { $tmpFile = CWebDavTmpFile::buildFromDownloaded($_FILES['file']); list($tmpFile->width, $tmpFile->height) = CFile::getImageSize($tmpFile->getAbsolutePath()); $newFile = clone $tmpFile; $newFile->filename = $filename; $newFile->isCloud = true; $newFile->bucketId = $bucket->ID; $newFile->append($tmpFile, compact('startRange', 'endRange', 'fileSize')); if (!$newFile->save()) { throw new Exception('Error in DB'); } } else { //simple upload $newFile = $this->createNewFile(); } return $this->sendSuccess(array('token' => $newFile->name)); } else { //if run resumable upload we needed token. $this->checkRequiredParams($params, array('token')); if (!($tmpResumableFile = CWebDavTmpFile::buildByName($params['token']))) { return $this->sendResponse(array('status' => static::STATUS_CHUNK_ERROR, 'message' => 'Not found file by token')); } $success = $tmpResumableFile->append(CWebDavTmpFile::buildFromDownloaded($_FILES['file']), compact('startRange', 'endRange', 'fileSize')); if ($success) { return $this->sendSuccess(array('token' => $tmpResumableFile->name)); } } } else { //simple upload $newFile = $this->createNewFile(); return $this->sendSuccess(array('token' => $newFile->name)); } }