3namespace Bitrix\UI\Controller;
5use Bitrix\Main\Engine\Action;
6use Bitrix\Main\Engine\ActionFilter;
7use Bitrix\Main\Engine\AutoWire\ExactParameter;
8use Bitrix\Main\Engine\AutoWire\Parameter;
9use Bitrix\Main\Engine\Controller;
10use Bitrix\Main\Engine\Response;
12use Bitrix\Main\Web\Json;
13use Bitrix\UI\FileUploader\Chunk;
14use Bitrix\UI\FileUploader\ControllerResolver;
15use Bitrix\UI\FileUploader\Uploader;
16use Bitrix\UI\FileUploader\UploaderController;
17use Bitrix\UI\FileUploader\UploaderError;
23 $configureActions = [];
25 $configureActions[
'preview'] = [
27 ActionFilter\Csrf::class,
28 ActionFilter\HttpMethod::class,
36 $configureActions[
'download'] = [
38 ActionFilter\Csrf::class,
39 ActionFilter\HttpMethod::class,
46 return $configureActions;
74 UploaderController::class,
76 function ($className,
string $controller,
string $controllerOptions =
null) {
79 $options = empty($controllerOptions) ? [] : Json::decode($controllerOptions);
87 if (is_subclass_of($this, FileUploader::class))
90 if ($availableControllers ===
null)
93 'You have to override "getAvailableControllers" method for your custom ajax controller.'
100 $className = strtolower(ltrim($className,
'\\'));
102 $availableNames = array_map(
function(
$name) {
103 return strtolower(ltrim(
$name,
'\\'));
104 }, $availableControllers);
107 !in_array(strtolower($controller), $availableNames)
108 && !in_array($className, $availableNames)
117 return ControllerResolver::createController($controller,
$options);
122 function ($className) use (
$request) {
126 return $result->getData()[
'chunk'];
141 $contentLength = (int)$this->
getRequest()->getServer()->get(
'CONTENT_LENGTH');
143 \CUtil::unformat(ini_get(
'upload_max_filesize')),
144 \CUtil::unformat(ini_get(
'post_max_size'))
147 if ($contentLength > $maxFileSize)
154 return parent::processBeforeAction(
$action);
159 $uploader =
new Uploader($controller);
160 $uploadResult = $uploader->upload($chunk, $token);
161 if ($uploadResult->isSuccess())
163 return $uploadResult->jsonSerialize();
167 $this->
addErrors($uploadResult->getErrors());
175 $uploader =
new Uploader($controller);
176 $loadResults = $uploader->load($fileIds);
179 'files' => $loadResults,
185 $uploader =
new Uploader($controller);
186 $loadResults = $uploader->load([$fileId]);
187 $loadResult = $loadResults->getAll()[0] ??
null;
189 if ($loadResult ===
null)
193 else if ($loadResult->isSuccess())
195 $fileId = $loadResult->getFile() ? $loadResult->getFile()->getFileId() : 0;
207 $this->
addErrors($loadResult->getErrors());
215 $uploader =
new Uploader($controller);
216 $loadResults = $uploader->load([$fileId]);
217 $loadResult = $loadResults->getAll()[0] ??
null;
219 if ($loadResult ===
null)
223 else if ($loadResult->isSuccess())
225 $imageId = $loadResult->getFile() ? $loadResult->getFile()->getFileId() : 0;
226 $imageData = \CFile::getFileArray($imageId);
228 if (is_array($imageData))
244 $this->
addErrors($loadResult->getErrors());
252 $uploader =
new Uploader($controller);
253 $removeResult = $uploader->remove($fileIds);
256 'files' => $removeResult,
static createByFileId($fileId, $name=null)
uploadAction(UploaderController $controller, Chunk $chunk, string $token=null)
getAvailableControllers()
loadAction(UploaderController $controller, array $fileIds)
processBeforeAction(Action $action)
previewAction(UploaderController $controller, string $fileId)
removeAction(UploaderController $controller, array $fileIds)
downloadAction(UploaderController $controller, string $fileId)
static createFromRequest(HttpRequest $request)
static resolveName(string $controllerName)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
const BX_RESIZE_IMAGE_PROPORTIONAL