Update meme voting

This commit is contained in:
2024-04-27 11:48:58 +02:00
parent 287c2050e0
commit adb738c12f
24 changed files with 43 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
function makePathSafe($userInput): string
{
@@ -68,11 +69,11 @@ function getIncomingFiles(): array
return $files3;
}
function saveUploadedFileInDatabase($filePath, $fileType): bool
function saveUploadedFileInDatabase(string $filePath, string $fileType, int $width, int $height): bool
{
global $mysqli;
$stmt = $mysqli->prepare("INSERT INTO Files (Path, Type, UploadedBy, UploadedAt) VALUES (?, ?, ?, NOW())");
$stmt->bind_param("ssi", $filePath, $fileType, $_SESSION["ID"]);
$stmt = $mysqli->prepare("INSERT INTO Files (Path, Type, UploadedBy, UploadedAt, Width, Height) VALUES (?, ?, ?, NOW(), ?, ?)");
$stmt->bind_param("ssiii", $filePath, $fileType, $_SESSION["ID"], $width, $height);
$stmt->execute();
$stat = $stmt->affected_rows > 0;
$stmt->close();
@@ -82,19 +83,23 @@ function saveUploadedFileInDatabase($filePath, $fileType): bool
function doImageUpload($inFile, $outFile): bool
{
// Create Imagick object
$width = 0;
$height = 0;
try {
$imagick = new Imagick($inFile);
$imagick->setImageFormat('webp');
autoRotateImage($imagick);
$imagick->stripImage();
$imagick->writeImage($outFile);
$width = $imagick->getImageWidth();
$height = $imagick->getImageHeight();
$imagick->destroy();
} catch (ImagickException) {
}
// Check if the reencoding was successful
if (file_exists($outFile)) {
return saveUploadedFileInDatabase($outFile, 'image/webp');
return saveUploadedFileInDatabase($outFile, 'image/webp', $width, $height);
} else {
return false;
}