diff --git a/.gitignore b/.gitignore index ad254d2..8c4bee2 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,4 @@ composer.phar /vendor/ /Backend/Database/test.db /Backend/Games/ +/Frontend/images/ diff --git a/Backend/Controllers/FileHandler/upload.php b/Backend/Controllers/FileHandler/upload.php index d532ee2..ab13d0e 100644 --- a/Backend/Controllers/FileHandler/upload.php +++ b/Backend/Controllers/FileHandler/upload.php @@ -2,44 +2,53 @@ require_once "../../../bootstrap.php"; use Backend\Models\GameData; - if(isset($_POST['submitUpload'])){ //Get the data from the user form $gameFile = $_FILES['gameFile']; $desc = $_POST['description']; $title = $_POST['gameTitle']; + $thumbnail = $_FILES['thumbnailFile']; $isWebBased = isset( $_POST['isWebBased']); //Handle data for game files $gameFileName = $_FILES['gameFile']['name'];//Game name $gameFileTmp = $_FILES['gameFile']['tmp_name'];//Tmp location of the file - $gameFileType =$_FILES['gameFile']['type'];//File type $gameFileError =$_FILES['gameFile']['error'];//File error + $fileExtGame = explode('.', $gameFileName); + $fileActualExtGame = strtolower(end($fileExtGame)); - $fileExt = explode('.', $gameFileName); - $fileActualExt = strtolower(end($fileExt)); + //Handle data for thumbnail files + $thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name + $thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file + $thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error + + $fileExtThumb = explode('.', $thumbnailFileName); + $fileActualExtThumb = strtolower(end($fileExtThumb)); - $allowedFileType = array('zip'); + $allowedFileTypeGame = array('zip'); + $allowedFileTypeThumbnail = array('gif', 'jpeg', 'png', 'svg'); - if(in_array($fileActualExt,$allowedFileType)){ - if($gameFileError === 0){ - $gameFileNewName = uniqid("", true). "." . $fileActualExt; + if(in_array($fileActualExtGame,$allowedFileTypeGame) || in_array($thumbnailFileName,$allowedFileTypeThumbnail)){ + if($gameFileError === 0 || $thumbnailFileError === 0){ + $gameFileNewName = uniqid("", true). "." . $fileActualExtGame; + $thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb; 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; $gameData->is_web_Based = $isWebBased; $gameData->save(); rename($gameFileTmp,"../../Games/".$gameFileNewName); + rename($thumbnailFileTmp,"../../../Frontend/images/".$fileActualExtThumb); } }else{ echo "Der var en fejl med at uploade din file"; diff --git a/Frontend/group.php b/Frontend/group.php index 2c2baee..d0a5e99 100644 --- a/Frontend/group.php +++ b/Frontend/group.php @@ -24,7 +24,10 @@

-

+

+ + +