/** * @param $file * @return boolean */ public function sendFile($file) { /** @var File $file */ $file = File::loadById($file['extra']['id']); if (!$file->canRead($this->storage->getCurrentUserSecurityContext())) { throw new CWebDavAccessDeniedException(); } return CFile::viewByUser($file->getFile(), array("force_download" => true)); }
/** * Sends file content. * * The method is invoked by \CRestUtil::METHOD_DOWNLOAD. * * @param int $id Id of file. * @throws AccessException * @throws RestException * @return void */ protected function download($id) { /** @var Disk\File $file */ $file = $this->get($id); $fileData = $file->getFile(); if (!$fileData) { throw new RestException('Could not get content of file'); } \CFile::viewByUser($fileData, array('force_download' => true, 'cache_time' => 0, 'attachment_name' => $file->getName())); }
public static function writeFileToResponse($fileID) { if (!Loader::includeModule('disk')) { return; } $file = File::loadById($fileID); if (!$file) { return; } $fileData = $file->getFile(); if (!$fileData) { return; } \CFile::viewByUser($fileData, array('force_download' => true, 'cache_time' => 0, 'attachment_name' => $file->getName())); }
protected function processActionDownload($showFile = false, $runResize = false) { if ($this->externalLink->hasPassword() && !$this->checkPassword()) { $this->showAccessDenied(); return false; } $file = $this->externalLink->getFile(); if (!$file) { $this->includeComponentTemplate('error'); return false; } if (!$this->externalLink->isAutomatic() && !$this->checkDownloadToken($file, $this->request->getQuery('token'))) { $this->includeComponentTemplate('error'); return false; } $this->externalLink->incrementDownloadCount(); if ($this->externalLink->isSpecificVersion()) { $version = $file->getVersion($this->externalLink->getVersionId()); if (!$version) { $this->includeComponentTemplate('error'); return false; } $fileData = $version->getFile(); } else { $fileData = $file->getFile(); } if (!$fileData) { $this->includeComponentTemplate('error'); return false; } if ($runResize && TypeFile::isImage($fileData['ORIGINAL_NAME'])) { /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $tmpFile = \CFile::resizeImageGet($fileData, array("width" => 255, "height" => 255), BX_RESIZE_IMAGE_EXACT, true, false, true); $fileData["FILE_SIZE"] = $tmpFile["size"]; $fileData["SRC"] = $tmpFile["src"]; } CFile::viewByUser($fileData, array('force_download' => !$showFile, 'attachment_name' => $file->getName())); }
protected function processActionDownloadFile() { $this->checkRequiredGetParams(array('attachedId')); if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } $fileModel = null; list($type, $realValue) = FileUserType::detectType($this->request->getQuery('attachedId')); if ($type == FileUserType::TYPE_NEW_OBJECT) { /** @var File $fileModel */ $fileModel = File::loadById((int) $realValue, array('STORAGE')); if (!$fileModel) { $this->errorCollection->add(array(new Error("Could not find file"))); $this->sendJsonErrorResponse(); } if (!$fileModel->canRead($fileModel->getStorage()->getCurrentUserSecurityContext())) { $this->errorCollection->add(array(new Error("Bad permission. Could not read this file"))); $this->sendJsonErrorResponse(); } $fileName = $fileModel->getName(); $fileData = $fileModel->getFile(); if (!$fileData) { $this->end(); } $cacheTime = 0; $width = $this->request->getQuery('width'); $height = $this->request->getQuery('height'); if (TypeFile::isImage($fileData["ORIGINAL_NAME"]) && ($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'); } /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $tmpFile = \CFile::resizeImageGet($fileData, array("width" => $width, "height" => $height), $this->request->getQuery('exact') == "Y" ? BX_RESIZE_IMAGE_EXACT : BX_RESIZE_IMAGE_PROPORTIONAL, true, false, true); $fileData["FILE_SIZE"] = $tmpFile["size"]; $fileData["SRC"] = $tmpFile["src"]; $cacheTime = 86400; } \CFile::viewByUser($fileData, array("force_download" => false, "cache_time" => $cacheTime, 'attachment_name' => $fileName)); } else { $this->errorCollection->add(array(new Error('Could not find attached object'))); $this->sendJsonErrorResponse(); } }
$componentPage = "section_edit_simple"; } elseif ($componentPage == "element_upload" && isset($_REQUEST["use_light_view"]) && strToUpper($_REQUEST["use_light_view"]) == "Y") { $componentPage = "element_upload_simple"; } elseif ($componentPage == "sections") { $arResult["VARIABLES"]["PATH"] = $ob->_path; if (!empty($ob->_path)) { $ob->IsDir(array('check_permissions' => false)); if ($ob->arParams["not_found"]) { $ob->SetStatus('404 not found'); } elseif (!empty($ob->arParams['file_name'])) { if (\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk')) { /** @var \Bitrix\Disk\File $diskFile */ $diskFile = \Bitrix\Disk\File::load(array('XML_ID' => $ob->arParams['element_array']['ID']), array('STORAGE')); if ($diskFile && $diskFile->getStorage()) { if ($diskFile->canRead($diskFile->getStorage()->getCurrentUserSecurityContext())) { CFile::viewByUser($diskFile->getFile(), array("force_download" => false)); } } } $APPLICATION->RestartBuffer(); $ob->base_GET(); die; } if (!empty($needToRedirectPageUrl)) { LocalRedirect($needToRedirectPageUrl); } $arResult["VARIABLES"]["SECTION_ID"] = $ob->arParams["item_id"]; } } if ($componentPage == "sections" && strpos($_SERVER["REQUEST_URI"], "dialog=Y") !== false) { $componentPage = "sections_dialog";
protected function processActionDownloadVersion() { $this->version = $this->file->getVersion($this->versionId); if (!$this->version) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOWNLOAD_CONTROLLER_ERROR_COULD_NOT_FIND_VERSION'), self::ERROR_COULD_NOT_FIND_VERSION))); $this->sendJsonErrorResponse(); } $fileData = $this->version->getFile(); \CFile::viewByUser($fileData, array("force_download" => false, 'cache_time' => 0, 'attachment_name' => $this->file->getName())); }
/** * @param $file * @throws AccessDeniedException * @return bool|void */ public function sendFile($file) { /** @var File $file */ $file = File::loadById($file['extra']['id']); if (!$file->canRead($this->storage->getCurrentUserSecurityContext())) { throw new AccessDeniedException(); } /** @noinspection PhpUndefinedClassInspection */ /** @noinspection PhpVoidFunctionResultUsedInspection */ return \CFile::viewByUser($file->getFile(), array("force_download" => true)); }
} if (empty($_REQUEST['objectId'])) { return; } /** @var File $file */ $file = File::loadById((int) $_REQUEST['objectId'], array('STORAGE')); if (!$file) { return; } $securityContext = $file->getStorage()->getCurrentUserSecurityContext(); if (!$file->canRead($securityContext)) { return; } if (!empty($_GET['download'])) { $fileData = $file->getFile(); \CFile::viewByUser($fileData, array("force_download" => false, 'attachment_name' => $file->getName())); } if (CFile::isImage($file->getName())) { $icon = 'img.png'; } else { $icons = array('pdf' => 'pdf.png', 'doc' => 'doc.png', 'docx' => 'doc.png', 'ppt' => 'ppt.png', 'pptx' => 'ppt.png', 'rar' => 'rar.png', 'xls' => 'xls.png', 'xlsx' => 'xls.png', 'zip' => 'zip.png'); $ext = strtolower(getFileExtension($file->getName())); $icon = isset($icons[$ext]) ? $icons[$ext] : 'blank.png'; } $arResult['NAME'] = $file->getName(); $arResult['SIZE'] = $file->getSize(); $arResult['CREATE_TIME'] = $file->getCreateTime(); $arResult['DATE_CREATE'] = $file->getUpdateTime(); $arResult['ICON'] = $this->getPath() . '/images/' . $icon; $arResult['DESCRIPTION'] = ''; $arResult['URL'] = SITE_DIR . "mobile/disk/{$file->getId()}/download" . '/' . mobileDiskPrepareForJson($file->getName());