diff --git a/app/Controllers/Api/Images/Upload.php b/app/Controllers/Api/Images/Upload.php index a49bc57..f7591e1 100644 --- a/app/Controllers/Api/Images/Upload.php +++ b/app/Controllers/Api/Images/Upload.php @@ -98,11 +98,16 @@ class Upload $upload = new UploadPhoto($outputImagePath, 'cdn/img/'); self::$vidpreview = $upload->getSrc(); $upload = new UploadPhoto($mp4File, 'cdn/video/'); + echo explode($mp4File, '.')[1]; self::$videourl = $upload->getSrc(); + $exif = Json::return( + array( + 'type' => 'none', + ) + ); } else if (explode($type, '/')[0] === 'image') { - $exif = new EXIF($_FILES['image']['tmp_name']); $exif = $exif->getData(); $upload = new UploadPhoto($_FILES['image'], 'cdn/img/'); diff --git a/app/Services/Upload.php b/app/Services/Upload.php index ec5461b..32a686d 100644 --- a/app/Services/Upload.php +++ b/app/Services/Upload.php @@ -24,9 +24,19 @@ class Upload } public function __construct($file, $location) { - + if (is_array($file)) { + $tmpname = $file['tmp_name']; + $type = explode('/', $file['type'])[0]; + $name = $file['name']; + $fileext = pathinfo($file['name']); + } else { + $tmpname = $file; + $type = filetype($file); + $name = basename($file); + $fileext = pathinfo($file, PATHINFO_EXTENSION); + } $cstrong = True; - $filecdn = bin2hex(openssl_random_pseudo_bytes(64, $cstrong)) . '.' . 'jpeg'; + $filecdn = bin2hex(openssl_random_pseudo_bytes(64, $cstrong)) . '.' . $fileext; $folder = $location . $filecdn; $s3 = new \Aws\S3\S3Client([ 'region' => NGALLERY['root']['storage']['s3']['credentials']['region'], @@ -37,16 +47,16 @@ class Upload ], 'endpoint' => NGALLERY['root']['storage']['s3']['domains']['gateway'], ]); - + $s3->putObject([ 'Bucket' => NGALLERY['root']['storage']['s3']['credentials']['bucket'], 'Key' => $location.$filecdn, - 'SourceFile' => $file['tmp_name'] + 'SourceFile' => $tmpname ]); - $this->type = explode('/', $file['type'])[0]; + $this->type = $type; $this->src = NGALLERY['root']['storage']['s3']['domains']['public'] . '/' . $location . $filecdn; - $this->size = self::human_filesize(filesize($file['tmp_name'])); - $this->name = $file['name']; + $this->size = self::human_filesize(filesize($tmpname)); + $this->name = $name; } public function getType() { diff --git a/views/pages/Photo.php b/views/pages/Photo.php index b70b3c8..c0dc5cc 100644 --- a/views/pages/Photo.php +++ b/views/pages/Photo.php @@ -104,8 +104,16 @@ if ($photo->i('id') !== null) {