diff --git a/app/Controllers/Api/Images/Upload.php b/app/Controllers/Api/Images/Upload.php index f7591e1..b63208c 100644 --- a/app/Controllers/Api/Images/Upload.php +++ b/app/Controllers/Api/Images/Upload.php @@ -105,7 +105,7 @@ class Upload 'type' => 'none', ) ); - } else if (explode($type, '/')[0] === 'image') { + } else if (explode('/', $type)[0] === 'image') { $exif = new EXIF($_FILES['image']['tmp_name']); diff --git a/app/Controllers/MainController.php b/app/Controllers/MainController.php index 5d1bf78..e6751f8 100644 --- a/app/Controllers/MainController.php +++ b/app/Controllers/MainController.php @@ -36,9 +36,7 @@ class MainController } public static function videoRules() { - $_GLOBAL['rules'] = '/config/videoRules.html'; - $_GLOBAL['title'] = 'Правила видеотеки'; - Page::set('Rules'); + Page::set('VideoRules'); } public static function update() { 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() { diff --git a/ngallery-example.yaml b/ngallery-example.yaml index cdbed3a..8373996 100644 --- a/ngallery-example.yaml +++ b/ngallery-example.yaml @@ -20,6 +20,10 @@ ngallery: websockets: messages: "" storage: + + # type: 's3' - загрузка файлов в хранилище S3 (Amazon S3, Cloudflare, MinIO и т.д) + # type: 'server' - загрузка файлов в папку uploads (hardcode) + type: 's3' s3: domains: diff --git a/uploads/.gitignore b/uploads/.gitignore new file mode 100644 index 0000000..e69de29