From 221dbcf0cc5cb125e31c29fe057945d5ff3711d5 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Fri, 19 Jul 2024 11:03:54 +0300 Subject: [PATCH] =?utf8?q?[ERP-88]=20=D0=90=D0=BF=D0=BB=D0=BE=D0=B0=D0=B4?= =?utf8?q?=20xlsx=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- docker/php/Dockerfile | 6 ++-- erp24/actions/motivation/UploadXlsxAction.php | 36 +++++++++++++++++++ erp24/composer.json | 3 +- erp24/controllers/MotivationController.php | 1 + erp24/views/motivation/upload-xlsx.php | 29 +++++++++++++++ 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 erp24/actions/motivation/UploadXlsxAction.php create mode 100644 erp24/views/motivation/upload-xlsx.php diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index d6386a79..2de2f1f1 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -1,11 +1,13 @@ -FROM php:7.4-rc-fpm-alpine +FROM php:8.1-fpm-alpine # Install tools required for build stage RUN apk add --update --no-cache \ bash curl wget rsync ca-certificates openssl openssh git tzdata openntpd \ libxrender fontconfig libc6-compat -RUN apk add --no-cache zlib libpng icu \ +RUN apk add --no-cache zlib libpng icu zip libzip-dev \ && apk add --no-cache --virtual .deps zlib-dev libpng-dev icu-dev \ + && docker-php-ext-configure zip \ + && docker-php-ext-install zip \ && docker-php-ext-install -j$(nproc) gd mysqli pdo pdo_mysql intl calendar opcache \ && apk del .deps diff --git a/erp24/actions/motivation/UploadXlsxAction.php b/erp24/actions/motivation/UploadXlsxAction.php new file mode 100644 index 00000000..ddd8f873 --- /dev/null +++ b/erp24/actions/motivation/UploadXlsxAction.php @@ -0,0 +1,36 @@ + null + ], [ + ['myfile', 'file', 'skipOnEmpty' => false, 'extensions' => 'xlsx'], + ]); + + if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) { + var_dump($_FILES); + if ($model->validate()) { + $xlsx = UploadedFile::getInstanceByName('myfile'); + var_dump($xlsx); + $path = 'uploads/' . date("YdmHis") . rand(1000, 9999); + $xlsx->saveAs($path); + var_dump(321); + } else { + var_dump($model->getErrors()); + var_dump(Yii::$app->request->post()); + } + } + + return $this->controller->render('upload-xlsx', + compact('model')); + } +} \ No newline at end of file diff --git a/erp24/composer.json b/erp24/composer.json index f6facf18..762e20ef 100644 --- a/erp24/composer.json +++ b/erp24/composer.json @@ -26,7 +26,8 @@ "unclead/yii2-multiple-input": "~2.0", "kartik-v/yii2-widget-fileinput": "dev-master", "yiisoft/yii2-imagine": "^2.3", - "kartik-v/yii2-builder": "dev-master" + "kartik-v/yii2-builder": "dev-master", + "box/spout": "^3.3" }, "require-dev": { "yiisoft/yii2-debug": "~2.1.0", diff --git a/erp24/controllers/MotivationController.php b/erp24/controllers/MotivationController.php index 8175a6e3..ec0813a6 100644 --- a/erp24/controllers/MotivationController.php +++ b/erp24/controllers/MotivationController.php @@ -10,6 +10,7 @@ class MotivationController extends Controller public function actions() { return [ 'index' => \yii_app\actions\motivation\IndexAction::class, + 'upload-xlsx' => \yii_app\actions\motivation\UploadXlsxAction::class, ]; } diff --git a/erp24/views/motivation/upload-xlsx.php b/erp24/views/motivation/upload-xlsx.php new file mode 100644 index 00000000..269cf1a0 --- /dev/null +++ b/erp24/views/motivation/upload-xlsx.php @@ -0,0 +1,29 @@ + + +
+ + ['enctype' => 'multipart/form-data']]) ?> + +
+
+
+
Excel file:
+
field($model, 'myfile')->fileInput()->label(false) ?>
+
+
+
'btn btn-success btn-sm'])?>
+
+
+
+ + + +
-- 2.39.5