Add file upload

This commit is contained in:
2024-04-25 10:19:24 +02:00
parent eb3086cb12
commit 2f49e6aa8a
5 changed files with 34 additions and 22 deletions

View File

@@ -1,12 +1,12 @@
<?php
function addMeme(string $memeText, int $imageID): bool
function addMeme(string $title, string $memeText, int $imageID): bool
{
global $mysqli;
if (isLoggedIn() && fileExists($imageID)) {
$stmtMemeAdd = $mysqli->prepare('INSERT INTO Memes (AuthorID, Title, TextContent, FileID) VALUES (?, ?, ?, ?)');
$stmtMemeAdd->bind_param('issi', $_SESSION['ID'], htmlspecialchars($memeText), $imageID);
$stmtMemeAdd->bind_param('issi', $_SESSION['ID'], htmlspecialchars($title), htmlspecialchars($memeText), $imageID);
$stmtMemeAdd->execute();
return true;
}

View File

@@ -59,30 +59,13 @@ function doImageUpload($inFile, $outFile): bool
// Create Imagick object
try {
$imagick = new Imagick($inFile);
} catch (ImagickException $e) {
}
// Set the desired format for reencoding (WebP)
try {
$imagick->setImageFormat('webp');
} catch (ImagickException $e) {
}
// Remove non-essential metadata
try {
$imagick->stripImage();
} catch (ImagickException $e) {
}
// Write the reencoded image to the output file
try {
$imagick->writeImage($outFile);
$imagick->destroy();
} catch (ImagickException $e) {
}
// Destroy the Imagick object to free up resources
$imagick->destroy();
// Check if the reencoding was successful
if (file_exists($outFile)) {
return saveUploadedFileInDatabase($outFile, 'image/webp');
@@ -207,7 +190,7 @@ function fileExists(int $fileId, bool $onlyMine = true): bool
return $stmtfileexists->affected_rows > 0;
}
function addToGroup(int $groupId, int $fileId): bool
function addToGroup(int $groupId, int $fileId): array
{
$output = ["Status" => "Fail"];
if (!$groupId || !$fileId) {