- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/uf/controller.php
- Класс: BitrixDiskUfController
- Вызов: Controller::processActionDownloadFile
protected function processActionDownloadFile(): void
{
$this->checkRequiredGetParams(['attachedId']);
if ($this->errorCollection->hasErrors())
{
$this->sendJsonErrorResponse();
}
[$type, $realValue] = FileUserType::detectType($this->request->getQuery('attachedId'));
if ($type === FileUserType::TYPE_NEW_OBJECT)
{
$fileModel = File::loadById((int)$realValue, ['STORAGE']);
if (!$fileModel)
{
$this->addError(new Error('Could not find file'));
$this->sendJsonErrorResponse();
}
if (!$fileModel->canRead($fileModel->getStorage()->getCurrentUserSecurityContext()))
{
$this->addError(new Error("Bad permission. Could not read this file"));
$this->sendJsonErrorResponse();
}
$fileName = $fileModel->getName();
$fileData = $fileModel->getFile();
if (!$fileData)
{
$this->end();
}
$cacheTime = 0;
$width = (int)$this->request->getQuery('width');
$height = (int)$this->request->getQuery('height');
$isImage = TypeFile::isImage($fileData['ORIGINAL_NAME']) || TypeFile::isImage($fileName);
$isImage = $isImage && !TypeFile::shouldTreatImageAsFile($fileData);
if ($isImage && ($width > 0 || $height > 0))
{
$signature = $this->request->getQuery('signature');
if (!$signature)
{
$this->sendJsonInvalidSignResponse('Empty signature');
}
if (!ParameterSigner::validateImageSignature($signature, $fileModel->getId(), $width, $height))
{
$this->sendJsonInvalidSignResponse('Invalid signature');
}
$resizeType = $this->request->getQuery('exact') === 'Y' ? BX_RESIZE_IMAGE_EXACT : BX_RESIZE_IMAGE_PROPORTIONAL;
$tmpFile = CFile::resizeImageGet($fileData, ['width' => $width, 'height' => $height], $resizeType, true, false, true);
$fileData['FILE_SIZE'] = $tmpFile['size'];
$fileData['SRC'] = $tmpFile['src'];
$cacheTime = 86400;
}
CFile::viewByUser($fileData, ['force_download' => false, 'cache_time' => $cacheTime, 'attachment_name' => $fileName]);
}
else
{
$this->addError(new Error('Could not find attached object'));
$this->sendJsonErrorResponse();
}
}