Added mime content type to filehandler
This commit is contained in:
parent
91e4d3df00
commit
e6a635065d
|
@ -2,17 +2,17 @@
|
||||||
/**
|
/**
|
||||||
* @param string $gameFileName
|
* @param string $gameFileName
|
||||||
* @param string $gameFileTmp
|
* @param string $gameFileTmp
|
||||||
* @return string|null
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function ZipFileHandler(string $gameFileName, string $gameFileTmp): ?string
|
function ZipFileHandler(string $gameFileName, string $gameFileTmp){
|
||||||
{
|
|
||||||
|
|
||||||
$fileExtGame = explode('.', $gameFileName);
|
$fileExtGame = explode('.', $gameFileName);
|
||||||
$fileActualExtGame = strtolower(end($fileExtGame));
|
$fileActualExtGame = strtolower(end($fileExtGame));
|
||||||
|
|
||||||
$allowedFileTypeGame = array('zip');
|
$headerType = mime_content_type($gameFileTmp);
|
||||||
if(in_array($fileActualExtGame,$allowedFileTypeGame)){
|
$headerTypeMatch = array('application/zip');
|
||||||
|
|
||||||
|
if(in_array($headerType,$headerTypeMatch)){
|
||||||
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
|
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
|
||||||
if(empty($gameFileName)){
|
if(empty($gameFileName)){
|
||||||
header("location: ../../../Frontend/index.php?error=emptyFile");
|
header("location: ../../../Frontend/index.php?error=emptyFile");
|
||||||
|
@ -20,27 +20,25 @@ function ZipFileHandler(string $gameFileName, string $gameFileTmp): ?string
|
||||||
}
|
}
|
||||||
rename($gameFileTmp,"../../Games/".$gameFileNewName);
|
rename($gameFileTmp,"../../Games/".$gameFileNewName);
|
||||||
return $gameFileNewName;
|
return $gameFileNewName;
|
||||||
|
}else{
|
||||||
|
header("location: location: ../../../Frontend/index.php?error=Wrong%20File%20Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $thumbnailFileName
|
* @param string $thumbnailFileName
|
||||||
* @param string $thumbnailFileTmp
|
* @param string $thumbnailFileTmp
|
||||||
* @return string|null
|
* @return string
|
||||||
*/
|
*/
|
||||||
function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp): ?string
|
function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp){
|
||||||
{
|
|
||||||
|
|
||||||
$fileExtThumb = explode('.', $thumbnailFileName);
|
$fileExtThumb = explode('.', $thumbnailFileName);
|
||||||
$fileActualExtThumb = strtolower(end($fileExtThumb));
|
$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;
|
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
|
||||||
if(empty($thumbnailFileName)){
|
if(empty($thumbnailFileName)){
|
||||||
header("location: ../../../Frontend/index.php?error=emptyFile");
|
header("location: ../../../Frontend/index.php?error=emptyFile");
|
||||||
|
@ -48,6 +46,8 @@ function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp):
|
||||||
}
|
}
|
||||||
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
|
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
|
||||||
return $thumbnailFileNewName;
|
return $thumbnailFileNewName;
|
||||||
|
}else{
|
||||||
|
header("location: location: ../../../Frontend/index.php?error=Wrong%20File%20Type");
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
Loading…
Reference in New Issue