From e594ab732d733542ee8db18dc06e21d3197f63a3 Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Sun, 21 Jul 2024 02:59:40 +0300 Subject: [PATCH] video upload --- app/Controllers/Api/Images/Upload.php | 7 ++++- app/Services/Upload.php | 24 ++++++++++++----- views/pages/Photo.php | 8 ++++++ views/pages/Profile/UploadPhoto.php | 38 ++++++++++++++++++++++++--- 4 files changed, 65 insertions(+), 12 deletions(-) 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) {
+ content('videourl') != null) { ?> + + + i('priority') === 1) { ?>
Условная публикация
i('priority') === 2) { ?> diff --git a/views/pages/Profile/UploadPhoto.php b/views/pages/Profile/UploadPhoto.php index 003ad98..bd480eb 100644 --- a/views/pages/Profile/UploadPhoto.php +++ b/views/pages/Profile/UploadPhoto.php @@ -807,14 +807,36 @@ $user = new User(Auth::userid());    Информация о лицензиях - - + +      +
+
@@ -849,8 +871,9 @@ $user = new User(Auth::userid()); type: "POST", url: '/api/upload', data: formData, - + xhr: function() { + $('#prgb').html('
0%
'); // Добавляем спиннер и блокируем кнопку во время загрузки //$("#r").html(''); @@ -860,7 +883,12 @@ $user = new User(Auth::userid()); var percentComplete = parseInt(((evt.loaded / evt.total) * 100)); console.log(evt.total); - // Обновляем прогресс загрузки + + + var elem = document.getElementById("myBar"); + elem.style.width = percentComplete + '%'; + elem.innerHTML = percentComplete + '%'; + scrollProgressBarWidth(percentComplete); } }, false); @@ -870,6 +898,7 @@ $user = new User(Auth::userid()); success: function(response) { + $('#prgb').html(''); try { var jsonData = JSON.parse(response); } catch (err) { @@ -941,6 +970,7 @@ $user = new User(Auth::userid()); } }, error: function(xhr, status, error) { + $('#prgb').html(''); $("#r").html(''); $("#prgtd").html(''); $("#prgrsg").html('');