video upload

This commit is contained in:
themohooks 2024-07-21 02:59:40 +03:00
parent b55c757352
commit e594ab732d
4 changed files with 65 additions and 12 deletions

View file

@ -98,11 +98,16 @@ class Upload
$upload = new UploadPhoto($outputImagePath, 'cdn/img/'); $upload = new UploadPhoto($outputImagePath, 'cdn/img/');
self::$vidpreview = $upload->getSrc(); self::$vidpreview = $upload->getSrc();
$upload = new UploadPhoto($mp4File, 'cdn/video/'); $upload = new UploadPhoto($mp4File, 'cdn/video/');
echo explode($mp4File, '.')[1];
self::$videourl = $upload->getSrc(); self::$videourl = $upload->getSrc();
$exif = Json::return(
array(
'type' => 'none',
)
);
} else if (explode($type, '/')[0] === 'image') { } else if (explode($type, '/')[0] === 'image') {
$exif = new EXIF($_FILES['image']['tmp_name']); $exif = new EXIF($_FILES['image']['tmp_name']);
$exif = $exif->getData(); $exif = $exif->getData();
$upload = new UploadPhoto($_FILES['image'], 'cdn/img/'); $upload = new UploadPhoto($_FILES['image'], 'cdn/img/');

View file

@ -24,9 +24,19 @@ class Upload
} }
public function __construct($file, $location) 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; $cstrong = True;
$filecdn = bin2hex(openssl_random_pseudo_bytes(64, $cstrong)) . '.' . 'jpeg'; $filecdn = bin2hex(openssl_random_pseudo_bytes(64, $cstrong)) . '.' . $fileext;
$folder = $location . $filecdn; $folder = $location . $filecdn;
$s3 = new \Aws\S3\S3Client([ $s3 = new \Aws\S3\S3Client([
'region' => NGALLERY['root']['storage']['s3']['credentials']['region'], 'region' => NGALLERY['root']['storage']['s3']['credentials']['region'],
@ -37,16 +47,16 @@ class Upload
], ],
'endpoint' => NGALLERY['root']['storage']['s3']['domains']['gateway'], 'endpoint' => NGALLERY['root']['storage']['s3']['domains']['gateway'],
]); ]);
$s3->putObject([ $s3->putObject([
'Bucket' => NGALLERY['root']['storage']['s3']['credentials']['bucket'], 'Bucket' => NGALLERY['root']['storage']['s3']['credentials']['bucket'],
'Key' => $location.$filecdn, '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->src = NGALLERY['root']['storage']['s3']['domains']['public'] . '/' . $location . $filecdn;
$this->size = self::human_filesize(filesize($file['tmp_name'])); $this->size = self::human_filesize(filesize($tmpname));
$this->name = $file['name']; $this->name = $name;
} }
public function getType() public function getType()
{ {

View file

@ -104,8 +104,16 @@ if ($photo->i('id') !== null) {
<div style="display:inline-block"> <div style="display:inline-block">
<div id="underphoto_frame"> <div id="underphoto_frame">
<div id="ph_frame"> <div id="ph_frame">
<?php
if ($photo->content('videourl') != null) { ?>
<video controls>
<source src="<?=$photo->content('videourl')?>">
</video>
<?php } else { ?>
<img onerror="errimg(); this.onerror = null;" class="nozoom" id="ph" src="<?= $photo->i('photourl') ?>" alt="" title="Фотография"> <img onerror="errimg(); this.onerror = null;" class="nozoom" id="ph" src="<?= $photo->i('photourl') ?>" alt="" title="Фотография">
<?php <?php
}
if ($photo->i('priority') === 1) { ?> if ($photo->i('priority') === 1) { ?>
<div class="underphoto s17" style="cursor:help" title="Фотография не удовлетворяет действующим на момент публикации критериям качества снимков."><i style="position:relative; top:1px" class="fas fa-info-circle"></i>&ensp;<b class="dot">Условная публикация</b></div> <div class="underphoto s17" style="cursor:help" title="Фотография не удовлетворяет действующим на момент публикации критериям качества снимков."><i style="position:relative; top:1px" class="fas fa-info-circle"></i>&ensp;<b class="dot">Условная публикация</b></div>
<?php } else if ($photo->i('priority') === 2) { ?> <?php } else if ($photo->i('priority') === 2) { ?>

View file

@ -807,14 +807,36 @@ $user = new User(Auth::userid());
</select> &nbsp; &nbsp;<a href="https://creativecommons.org/licenses/?lang=ru" target="_blank" class="und sm">Информация о лицензиях</a> </select> &nbsp; &nbsp;<a href="https://creativecommons.org/licenses/?lang=ru" target="_blank" class="und sm">Информация о лицензиях</a>
</td> </td>
</tr> </tr>
<style>
.w3-green, .w3-hover-green:hover {
color: #fff !important;
background-color: #000 !important;
}
.w3-center {
text-align: center !important;
}
.w3-container, .w3-panel {
padding: 0.01em 16px;
}
.w3-light-grey, .w3-hover-light-grey:hover, .w3-light-gray, .w3-hover-light-gray:hover {
color: #000 !important;
background-color: #f1f1f1 !important;
}
.w3-container:after, .w3-container:before, .w3-panel:after, .w3-panel:before, .w3-row:after, .w3-row:before, .w3-row-padding:after, .w3-row-padding:before, .w3-cell-row:before, .w3-cell-row:after, .w3-clear:after, .w3-clear:before, .w3-bar:before, .w3-bar:after {
content: "";
display: table;
clear: both;
}
</style>
<tr> <tr>
<td></td> <td></td>
<td style="padding:20px 2px 12px"> <td style="padding:20px 2px 12px">
<button id="submitbtn" href="#" class="progress-button" data-loading="Идёт загрузка..." data-finished="Обработка..." type="submit">Опубликовать</button> &nbsp; &nbsp;&nbsp; <button id="submitbtn" href="#" class="progress-button" data-loading="Идёт загрузка..." data-finished="Обработка..." type="submit">Опубликовать</button> &nbsp; &nbsp;&nbsp;
<span id="statusbox" class="narrow" style="font-size:20px; font-weight:bold; position:relative; top:-12px"></span> <span id="statusbox" class="narrow" style="font-size:20px; font-weight:bold; position:relative; top:-12px"></span>
<div id="errorsbox" style="display:none; color:red; margin-top:15px; font-weight:bold;"></div> <div id="errorsbox" style="display:none; color:red; margin-top:15px; font-weight:bold;"></div>
<div style="margin-top: 20px; max-width: 50% !important;" id="prgb" class="w3-light-grey">
</div>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -849,8 +871,9 @@ $user = new User(Auth::userid());
type: "POST", type: "POST",
url: '/api/upload', url: '/api/upload',
data: formData, data: formData,
xhr: function() { xhr: function() {
$('#prgb').html('<div id="myBar" class="w3-container w3-green w3-center" style="width:0%">0%</div>');
// Добавляем спиннер и блокируем кнопку во время загрузки // Добавляем спиннер и блокируем кнопку во время загрузки
//$("#r").html('<button type="submit" id="register" name="loginaccount" class="btn btn-block btn-primary py-2 ripple-handler mt-1 mb-3" disabled><div class="plus-button-reflection"></div>Опубликовать</button>'); //$("#r").html('<button type="submit" id="register" name="loginaccount" class="btn btn-block btn-primary py-2 ripple-handler mt-1 mb-3" disabled><div class="plus-button-reflection"></div>Опубликовать</button>');
@ -860,7 +883,12 @@ $user = new User(Auth::userid());
var percentComplete = parseInt(((evt.loaded / evt.total) * 100)); var percentComplete = parseInt(((evt.loaded / evt.total) * 100));
console.log(evt.total); console.log(evt.total);
// Обновляем прогресс загрузки
var elem = document.getElementById("myBar");
elem.style.width = percentComplete + '%';
elem.innerHTML = percentComplete + '%';
scrollProgressBarWidth(percentComplete); scrollProgressBarWidth(percentComplete);
} }
}, false); }, false);
@ -870,6 +898,7 @@ $user = new User(Auth::userid());
success: function(response) { success: function(response) {
$('#prgb').html('');
try { try {
var jsonData = JSON.parse(response); var jsonData = JSON.parse(response);
} catch (err) { } catch (err) {
@ -941,6 +970,7 @@ $user = new User(Auth::userid());
} }
}, },
error: function(xhr, status, error) { error: function(xhr, status, error) {
$('#prgb').html('');
$("#r").html('<button type="submit" id="register" name="loginaccount" class="btn btn-block btn-primary py-2 ripple-handler mt-1 mb-3">Опубликовать<span class="ripple-mask"><span class="ripple" style=""></span></span></button>'); $("#r").html('<button type="submit" id="register" name="loginaccount" class="btn btn-block btn-primary py-2 ripple-handler mt-1 mb-3">Опубликовать<span class="ripple-mask"><span class="ripple" style=""></span></span></button>');
$("#prgtd").html(''); $("#prgtd").html('');
$("#prgrsg").html(''); $("#prgrsg").html('');