From: fomichev Date: Wed, 12 Feb 2025 13:32:26 +0000 (+0300) Subject: Чистка кода X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=ea0077b64fe4ea215d098b8cf348a3a2d1cc5689;p=erp24_rep%2Fyii-erp24%2F.git Чистка кода --- diff --git a/erp24/controllers/FilesController.php b/erp24/controllers/FilesController.php index 2ae4f48e..06bcf01f 100755 --- a/erp24/controllers/FilesController.php +++ b/erp24/controllers/FilesController.php @@ -13,31 +13,11 @@ use yii_app\services\FileService; class FilesController extends \yii\web\Controller { public $defaultAction = 'download'; - public $enableCsrfValidation = false; + public function actions() { return [ 'download' => \yii_app\actions\files\DownloadAction::class, ]; } - - public function actionUpload() - { - Yii::error(Yii::$app->request->post(), 'upload'); - Yii::error($_FILES, 'upload'); - file_put_contents(Yii::getAlias('@runtime/logs/upload.log'), print_r($_FILES, true), FILE_APPEND); - - $file = UploadedFile::getInstanceByName('upload'); - if (!$file) { - throw new BadRequestHttpException('No file uploaded.'); - } - - $filePath = FileService::saveUploadFileAndReturnUrl($file); - - $fullUrl = Yii::$app->request->hostInfo . '/web' . $filePath; - - file_put_contents(Yii::getAlias('@runtime/logs/upload.log'), print_r($fullUrl, true), FILE_APPEND); - - return $this->asJson(['url' => $fullUrl]); - } } diff --git a/erp24/services/FileService.php b/erp24/services/FileService.php index 3f0e1aa0..31bee4fd 100755 --- a/erp24/services/FileService.php +++ b/erp24/services/FileService.php @@ -161,21 +161,6 @@ class FileService return '/' . $targetFile; } - public static function saveUploadFileAndReturnUrl($file) { - $targetDir = Yii::getAlias('@webroot/uploads') . '/' . Yii::$app->user->id . '/' . date("Y") . "/" . date("m") . "/" . date("d"); - - if (!is_dir($targetDir)) { - mkdir($targetDir, 0777, true); - } - - $targetFile = $targetDir . "/" . substr(md5_file($file->tempName), 0, 8) . '_' . $file->baseName . '.' . $file->extension; - $file->saveAs($targetFile); - - $relativePath = str_replace(Yii::getAlias('@webroot'), '', $targetFile); - - return $relativePath; - } - public static function saveUploadedImage($file, $entity, $entity_id) { $imagePath = \Yii::getAlias('@uploads-images-path'); $target_dir = $imagePath . '/' . Yii::$app->user->id . '/' . date("Y") . "/" . date("m") . "/" . date("d");