From a2fe36227bfaa0315a88b1f4b0bb48fab5ba6243 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Tue, 5 Jul 2022 19:17:11 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=84=D0=B8=D0=BB=D1=8C=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=B0=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/inc/header.php | 2 +- admin/profile.php | 111 ++++++++++++++++++++++++++++ core/lib/Core/Models/File.class.php | 23 ++++-- 3 files changed, 128 insertions(+), 8 deletions(-) create mode 100644 admin/profile.php diff --git a/admin/inc/header.php b/admin/inc/header.php index c3b5302..1a21a06 100644 --- a/admin/inc/header.php +++ b/admin/inc/header.php @@ -196,7 +196,7 @@
- +
diff --git a/admin/profile.php b/admin/profile.php new file mode 100644 index 0000000..c45c783 --- /dev/null +++ b/admin/profile.php @@ -0,0 +1,111 @@ + + + +
+ +
+
+ $_POST['name'], 'email' => $_POST['email']]; + if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) { + $File = new File(); + $File->saveFile($_FILES['image']['tmp_name'], $_FILES['image']['name'], true); + $newUserFields['image'] = $File->getPath(); + } + + $USER->update($newUserFields); + ?> +
+ + Профиль успешно обновлен +
+
+
+ +
+
+
+
+

getName(); ?>

+

getAllUserData()['date_created']; ?>

+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+
+ + +
+
+ +
+ +
+ +
+
+ + +
+
+
+ + +
+ + +
+ +
+ \ No newline at end of file diff --git a/core/lib/Core/Models/File.class.php b/core/lib/Core/Models/File.class.php index f96b451..2feccca 100644 --- a/core/lib/Core/Models/File.class.php +++ b/core/lib/Core/Models/File.class.php @@ -167,19 +167,28 @@ return end(explode('.', $filename)); } - public function saveFile(string $filePath, ?string $fileName = null): self + public function saveFile(string $filePath, ?string $fileName = null, bool $useMove = false): self { - $storageFileName = md5(time() . $fileName . rand(1, 9999)) . '.' . static::getExt($filePath); - $storageFullPath = $this->folder . '/' . $storageFileName; + $storageFileName = md5(time() . $fileName . rand(1, 9999)); if (empty($fileName)) { - $fileName = $storageFileName; + $fileName = $storageFileName . '.' . static::getExt($filePath); + $storageFileName .= '.' . static::getExt($filePath); + } else { + $storageFileName .= '.' . static::getExt($fileName); } + $storageFullPath = $this->folder . '/' . $storageFileName; - if (!copy($filePath, $storageFullPath)) { - throw new CoreException('Не удалось скопировать файл', CoreException::ERROR_FILE_COPY); + if($useMove) { + if (!move_uploaded_file($filePath, $storageFullPath)) { + throw new CoreException('Не удалось скопировать загруженный файл', CoreException::ERROR_FILE_COPY); + } + } else { + if (!copy($filePath, $storageFullPath)) { + throw new CoreException('Не удалось скопировать файл', CoreException::ERROR_FILE_COPY); + } } $this->name = $fileName; - $this->path = $storageFullPath; + $this->path = self::FOLDER . '/' . $storageFileName; $this->id = $this->DB->addItem(self::TABLE, ['name' => $this->name, 'path' => $this->path]);