diff --git a/assets/script.js b/assets/script.js index 6948d7a..5a311dc 100644 --- a/assets/script.js +++ b/assets/script.js @@ -537,4 +537,24 @@ if ("loading" === document.readyState) { document.addEventListener("DOMContentLoaded", initAjax); } else { setTimeout(initAjax, 0); +} + +function uploadFile() { + const fileInput = document.getElementById('fileInput'); + const file = fileInput.files[0]; + let formData = new FormData(); + formData.append('userfile', file); + + let xhr = new XMLHttpRequest(); + xhr.open('POST', '__URL__', true); + + xhr.onload = function () { + if (xhr.status === 200) { + document.getElementById('uploadStatus').innerHTML = 'File uploaded successfully.'; + } else { + document.getElementById('uploadStatus').innerHTML = 'Error uploading file.'; + } + }; + + xhr.send(formData); } \ No newline at end of file diff --git a/endpoints/meme.php b/endpoints/meme.php index 8b4b1c1..82a0d5e 100644 --- a/endpoints/meme.php +++ b/endpoints/meme.php @@ -6,7 +6,7 @@ function endpoint($endpoint_data): array { return match ($endpoint_data["action"]) { - "addMeme" => addMeme($endpoint_data['memetext'], $endpoint_data['imageid']), + "addMeme" => addMeme($endpoint_data['memetitle'], $endpoint_data['memetext'], $endpoint_data['imageid']), "renderGallery" => renderMemeGallery(), default => ["Status" => "Fail", "message" => "Invalid action"], }; diff --git a/lib/meme.php b/lib/meme.php index fcf0650..2da7076 100644 --- a/lib/meme.php +++ b/lib/meme.php @@ -1,12 +1,12 @@ 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; } diff --git a/lib/upload.php b/lib/upload.php index a7ceed0..4145600 100644 --- a/lib/upload.php +++ b/lib/upload.php @@ -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) { diff --git a/pages/home/upload.html b/pages/home/upload.html new file mode 100644 index 0000000..9da0c16 --- /dev/null +++ b/pages/home/upload.html @@ -0,0 +1,9 @@ + + +
+ + + + +
+