/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/components/UploadHandler.php
113 строк
3 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\components; use common\helpers\FileHelper; use Yii; use yii\helpers\ArrayHelper; use yii\helpers\VarDumper; require_once Yii::getAlias('@bower/blueimp-file-upload/server/php/UploadHandler.php'); /** * Обработчик для загрузки файлов * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2021 */ class UploadHandler extends \UploadHandler { /** * @inheritdoc */ protected function get_unique_filename( $file_path, $name, $size, $type, $error, $index, $content_range ) { return FileHelper::genName($name); } /** * @inheritdoc */ protected function handle_file_upload( $uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null ) { $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); $file->title = $name; return $file; } /** * @inheritdoc */ protected function get_upload_data($id) { return ['tmp_name' => null]; } protected function get_upload_path($file_name = null, $version = null) { $path = parent::get_upload_path($file_name, $version); Yii::debug(VarDumper::dumpAsString(['path' => $path])); return $path; } /** * @inheritdoc */ public function generate_response($content, $print_response = true) { $callback = ArrayHelper::getValue($this->options, 'callback'); if (is_object($callback)) { try { $content = call_user_func($callback, $content); } catch (\Exception $e) { throw $e; } catch (\Throwable $e) { throw $e; } } elseif (is_array($callback)) { try { // дополнительная обработка для изображения $method = new \ReflectionMethod($content); // параметры в функцию $params[] = $content; // дополнительные параметры в функцию if ($ex_params = ArrayHelper::getValue($callback, 2)) { foreach ($ex_params as $param) { $params[] = $param; } } $content = $method->invokeArgs( null, $params ); } catch (\Exception $e) { throw $e; } catch (\Throwable $e) { throw $e; } } return parent::generate_response($content, false); } }