From b7112238c3144b386ff58d962f56a53145ddfbb9 Mon Sep 17 00:00:00 2001 From: GeorgNation <55389952+GeorgNation@users.noreply.github.com> Date: Tue, 23 Jul 2024 14:25:16 +0600 Subject: [PATCH] =?UTF-8?q?#7=20=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20=D0=B2=20=D0=BF?= =?UTF-8?q?=D0=B0=D0=BF=D0=BA=D1=83=20uploads?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ref #7 --- app/Services/Upload.php | 52 ++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/app/Services/Upload.php b/app/Services/Upload.php index 32a686d..d0c6bd7 100644 --- a/app/Services/Upload.php +++ b/app/Services/Upload.php @@ -38,25 +38,39 @@ class Upload $cstrong = True; $filecdn = bin2hex(openssl_random_pseudo_bytes(64, $cstrong)) . '.' . $fileext; $folder = $location . $filecdn; - $s3 = new \Aws\S3\S3Client([ - 'region' => NGALLERY['root']['storage']['s3']['credentials']['region'], - 'version' => NGALLERY['root']['storage']['s3']['credentials']['version'], - 'credentials' => [ - 'key' => NGALLERY['root']['storage']['s3']['credentials']['key'], - 'secret' => NGALLERY['root']['storage']['s3']['credentials']['secret'], - ], - 'endpoint' => NGALLERY['root']['storage']['s3']['domains']['gateway'], - ]); - - $s3->putObject([ - 'Bucket' => NGALLERY['root']['storage']['s3']['credentials']['bucket'], - 'Key' => $location.$filecdn, - 'SourceFile' => $tmpname - ]); - $this->type = $type; - $this->src = NGALLERY['root']['storage']['s3']['domains']['public'] . '/' . $location . $filecdn; - $this->size = self::human_filesize(filesize($tmpname)); - $this->name = $name; + + if (strtolower (NGALLERY['root']['storage']['type']) == "s3") + { + $s3 = new \Aws\S3\S3Client([ + 'region' => NGALLERY['root']['storage']['s3']['credentials']['region'], + 'version' => NGALLERY['root']['storage']['s3']['credentials']['version'], + 'credentials' => [ + 'key' => NGALLERY['root']['storage']['s3']['credentials']['key'], + 'secret' => NGALLERY['root']['storage']['s3']['credentials']['secret'], + ], + 'endpoint' => NGALLERY['root']['storage']['s3']['domains']['gateway'], + ]); + + $s3->putObject([ + 'Bucket' => NGALLERY['root']['storage']['s3']['credentials']['bucket'], + 'Key' => $location.$filecdn, + 'SourceFile' => $tmpname + ]); + $this->type = $type; + $this->src = NGALLERY['root']['storage']['s3']['domains']['public'] . '/' . $location . $filecdn; + $this->size = self::human_filesize(filesize($tmpname)); + $this->name = $name; + } + else + { + @mkdir ("{$_SERVER['DOCUMENT_ROOT']}/uploads/{$location}"); + move_uploaded_file ($tmpname, "{$_SERVER['DOCUMENT_ROOT']}/uploads/{$folder}"); + + $this->type = $type; + $this->src = "/uploads/{$folder}"; + $this->size = self::human_filesize(filesize($tmpname)); + $this->name = $name; + } } public function getType() {