- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/bitrix24disk/legacy/diskstorage.php
- Класс: BitrixDiskBitrix24DiskLegacyDiskStorage
- Вызов: DiskStorage::addFile
public function addFile($name, $targetDirectoryId, TmpFile $tmpFile, array $data = array())
{
$this->addShutdownTask(function() use($tmpFile){
$tmpFile->delete();
});
if(!$targetDirectoryId)
{
$folder = $this->storage->getRootObject();
}
else
{
$folder = Folder::loadById($targetDirectoryId);
}
/** @var Folder $folder */
if(!$folder)
{
$this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " by id {$targetDirectoryId}", 11152)));
return array();
}
if(!$folder->canAdd($this->storage->getSecurityContext($this->userId)))
{
throw new AccessDeniedException;
}
/** @var array $fileArray */
if($tmpFile->isCloud() && $tmpFile->getContentType())
{
$fileId = CFile::saveFile(array(
'name' => $tmpFile->getFilename(),
'tmp_name' => $tmpFile->getAbsolutePath(),
'type' => $tmpFile->getContentType(),
'width' => $tmpFile->getWidth(),
'height' => $tmpFile->getHeight(),
'MODULE_ID' => Driver::INTERNAL_MODULE_ID,
), Driver::INTERNAL_MODULE_ID, true, true);
if(!$fileId)
{
$this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", save cloud file", 111588)));
return array();
}
$fileArray = CFile::getFileArray($fileId);
if(!$fileArray)
{
$this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", getFileArray", 191588)));
return array();
}
$fileData = array(
'NAME' => $name,
'FILE_ID' => $fileId,
'SIZE' => !isset($data['SIZE'])? $fileArray['FILE_SIZE'] : $data['SIZE'],
'CREATED_BY' => $this->getUser()->getId(),
);
if(!empty($data['originalTimestamp']))
{
$fileData['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp']));
}
$fileModel = $folder->addFile($fileData);
if(!$fileModel)
{
CFile::delete($fileId);
}
}
else
{
$fileArray = CFile::makeFileArray($tmpFile->getAbsolutePath());
if(!$fileArray)
{
$this->errorCollection->addOne(new Error("Could not " . __METHOD__ . " MakeFileArray", 110155));
return array();
}
$fileArray['name'] = $name;
$fileData = array('NAME' => $name, 'CREATED_BY' => $this->getUser()->getId());
if(!empty($data['originalTimestamp']))
{
$fileData['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp']));
}
$fileArray['no_rotate'] = true;
$fileModel = $folder->uploadFile($fileArray, $fileData);
//it's crutch. There is process of name correction in uploadFile but we don't want to do it.
//And we don't want to add new parameters to manage it. In this case we restore name by renaming.
if ($fileModel && $fileModel->getName() != $name)
{
$fileModel->rename($name);
}
}
if($fileModel)
{
if (TypeFile::isImage($fileModel))
{
$this->processImageRotate($tmpFile, $fileModel);
}
$fileModel->changeEtag($tmpFile->getToken());
$this->loadTree();
$response = $this->formatFileToResponse($fileModel);
Driver::getInstance()->sendEvent($this->userId, 'fileUploaded', $response);
return $response;
}
$this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", uploadFile to {$targetDirectoryId}", 11153)));
$this->errorCollection->add($folder->getErrors());
return array();
}