diff --git a/Backend/Controllers/FileHandler/FileHandler.php b/Backend/Controllers/FileHandler/FileHandler.php index 4287865..7abe854 100644 --- a/Backend/Controllers/FileHandler/FileHandler.php +++ b/Backend/Controllers/FileHandler/FileHandler.php @@ -2,17 +2,17 @@ /** * @param string $gameFileName * @param string $gameFileTmp - * @return string|null + * @return string */ -function ZipFileHandler(string $gameFileName, string $gameFileTmp): ?string -{ - +function ZipFileHandler(string $gameFileName, string $gameFileTmp){ $fileExtGame = explode('.', $gameFileName); $fileActualExtGame = strtolower(end($fileExtGame)); - $allowedFileTypeGame = array('zip'); - if(in_array($fileActualExtGame,$allowedFileTypeGame)){ + $headerType = mime_content_type($gameFileTmp); + $headerTypeMatch = array('application/zip'); + + if(in_array($headerType,$headerTypeMatch)){ $gameFileNewName = uniqid("", true). "." . $fileActualExtGame; if(empty($gameFileName)){ header("location: ../../../Frontend/index.php?error=emptyFile"); @@ -20,27 +20,25 @@ function ZipFileHandler(string $gameFileName, string $gameFileTmp): ?string } rename($gameFileTmp,"../../Games/".$gameFileNewName); return $gameFileNewName; + }else{ + header("location: location: ../../../Frontend/index.php?error=Wrong%20File%20Type"); } - - - return NULL; } /** * @param string $thumbnailFileName * @param string $thumbnailFileTmp - * @return string|null + * @return string */ -function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp): ?string -{ - +function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp){ $fileExtThumb = explode('.', $thumbnailFileName); $fileActualExtThumb = strtolower(end($fileExtThumb)); - $allowedFileTypeThumbnail = array('gif', 'jpeg', 'png', 'svg', 'jpg', 'jfif', 'pjpeg', 'pjp', 'webp'); + $headerType = mime_content_type($thumbnailFileTmp); + $headerTypeMatch = array('image/png', 'image/jpeg','image/gif', 'image/svg+xml',); - if(in_array($fileActualExtThumb,$allowedFileTypeThumbnail)){ + if(in_array($headerType,$headerTypeMatch)){ $thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb; if(empty($thumbnailFileName)){ header("location: ../../../Frontend/index.php?error=emptyFile"); @@ -48,6 +46,8 @@ function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp): } rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName); return $thumbnailFileNewName; + }else{ + header("location: location: ../../../Frontend/index.php?error=Wrong%20File%20Type"); } return NULL; } \ No newline at end of file