Added mime content type to filehandler

This commit is contained in:
neerholt 2021-03-12 14:06:10 +01:00
parent 91e4d3df00
commit e6a635065d
1 changed files with 15 additions and 15 deletions

View File

@ -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;
}