- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/controller/export.php
- Класс: BitrixMainControllerExport
- Вызов: Export::uploadAction
public function uploadAction()
{
$chunkSize = $this->getSizeTempFile();
$isUploadStarted = ($this->uploadedPart > 0);
if (!$isUploadStarted)
{
$reservedSize = round($chunkSize * ceil($this->totalItems / $this->pageSize) * 1.5);
$this->uploadPath = $this->generateUploadDir(). $this->fileName;
$this->findInitBucket(array(
'fileSize' => $reservedSize,
'fileName' => $this->uploadPath,
));
if ($this->checkCloudErrors())
{
$this->saveProgressParameters();
if ($this->bucket->FileExists($this->uploadPath))
{
if(!$this->bucket->DeleteFile($this->uploadPath))
{
$this->addError(new Error('File exists in a cloud.'));
}
}
}
}
else
{
$this->instanceBucket();
$this->checkCloudErrors();
}
if (!file_exists($this->filePath))
{
$this->addError(new Error('Uploading file not exists.'));
}
if (!empty($this->getErrors()))
{
return AjaxJson::createError($this->errorCollection);
}
$isSuccess = false;
if ($this->isExportCompleted && !$isUploadStarted)
{
// just only one file
$uploadFile = array(
'name' => $this->fileName,
'size' => $this->fileSize,
'type' => $this->fileType,
'tmp_name' => $this->filePath,
);
if ($this->bucket->SaveFile($this->uploadPath, $uploadFile))
{
$this->uploadedPart ++;
$this->uploadedSize += $chunkSize;
$isSuccess = true;
$this->isUploadFinished = true;
}
else
{
$this->addError(new Error('Uploading error.'));
}
}
else
{
$uploader = new CCloudStorageUpload($this->uploadPath);
if (!$uploader->isStarted())
{
if (!$uploader->Start($this->bucketId, $reservedSize, $this->fileType))
{
$this->addError(new Error('Start uploading error.'));
return AjaxJson::createError($this->errorCollection);
}
}
$part = $this->getContentTempFile();
while ($uploader->hasRetries())
{
if ($uploader->Next($part, $this->bucket))
{
$this->uploadedPart ++;
$this->uploadedSize += $chunkSize;
$isSuccess = true;
break;
}
}
unset($part);
// finish
if ($isSuccess && $this->isExportCompleted)
{
if ($uploader->Finish())
{
$this->isUploadFinished = true;
}
else
{
$this->addError(new Error('FILE_UNKNOWN_ERROR'));
}
}
}
if ($isSuccess)
{
$this->dropTempFile();
}
// Save progress
$this->saveProgressParameters();
// continue export into temporally file
$result = $this->preformAnswer(self::ACTION_UPLOAD);
$result['STATUS'] = self::STATUS_PROGRESS;
return $result;
}