From c880cbf48cf8c88a7c06c2cf3708dc0143662e73 Mon Sep 17 00:00:00 2001 From: neerholt Date: Tue, 9 Mar 2021 13:17:18 +0100 Subject: [PATCH] images fix --- Backend/Controllers/FileHandler/upload.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Backend/Controllers/FileHandler/upload.php b/Backend/Controllers/FileHandler/upload.php index ab13d0e..0adc277 100644 --- a/Backend/Controllers/FileHandler/upload.php +++ b/Backend/Controllers/FileHandler/upload.php @@ -2,6 +2,8 @@ require_once "../../../bootstrap.php"; use Backend\Models\GameData; +$isImages = false; + if(isset($_POST['submitUpload'])){ //Get the data from the user form $gameFile = $_FILES['gameFile']; @@ -34,21 +36,30 @@ if(isset($_POST['submitUpload'])){ if(in_array($fileActualExtGame,$allowedFileTypeGame) || in_array($thumbnailFileName,$allowedFileTypeThumbnail)){ if($gameFileError === 0 || $thumbnailFileError === 0){ $gameFileNewName = uniqid("", true). "." . $fileActualExtGame; - $thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb; + + if(!empty($thumbnailFileName)){ + $thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb; + $isImages = true; + } + if(empty($gameFileName)){ header("location: ../../../Frontend/index.php?error=emptyFile"); exit(); }else{ + $gameData = new GameData(); $gameData->game_name = $title; $gameData->game_link = $gameFileNewName; $gameData->description = $desc; - $gameData->img = $thumbnailFileNewName; + if($isImages) $gameData->img = $thumbnailFileNewName; $gameData->is_web_Based = $isWebBased; $gameData->save(); rename($gameFileTmp,"../../Games/".$gameFileNewName); - rename($thumbnailFileTmp,"../../../Frontend/images/".$fileActualExtThumb); + if($isImages){ + rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName); + } + } }else{ echo "Der var en fejl med at uploade din file";