From bae523b62b74378ab5863aa9902fc89686b1fcb4 Mon Sep 17 00:00:00 2001 From: rodude123 Date: Mon, 26 Jun 2023 03:56:48 +0100 Subject: [PATCH] Uploaded imgUtils.php file Signed-off-by: rodude123 --- dist/api/utils/imgUtils.php | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 dist/api/utils/imgUtils.php diff --git a/dist/api/utils/imgUtils.php b/dist/api/utils/imgUtils.php new file mode 100644 index 0000000..40f9487 --- /dev/null +++ b/dist/api/utils/imgUtils.php @@ -0,0 +1,43 @@ +getClientFilename()); + $uploadOk = 1; + $imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION)); + + // Check if file already exists + if (file_exists($targetFile)) + { + return "The file already exists"; + } + + // Check file size + if ($img->getSize() > 2000000) + { + return "The file is too large, max 2MB"; + } + + // Allow certain file formats + if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") + { + return "Only JPG, JPEG, PNG & GIF files are allowed"; + } + + $img->moveTo($targetFile); + + return array("imgLocation" => $targetFile); + } +} \ No newline at end of file