Game-Jaming/Backend/Controllers/FileHandler/FileHandler.php

53 lines
1.8 KiB
PHP
Raw Normal View History

2021-03-09 14:04:59 +00:00
<?php
/**
2021-03-10 08:46:22 +00:00
* @param string $gameFileName
* @param string $gameFileTmp
2021-03-12 13:06:10 +00:00
* @return string
2021-03-09 14:04:59 +00:00
*/
2021-03-12 13:06:10 +00:00
function ZipFileHandler(string $gameFileName, string $gameFileTmp){
2021-03-09 14:04:59 +00:00
$fileExtGame = explode('.', $gameFileName);
$fileActualExtGame = strtolower(end($fileExtGame));
2021-03-12 13:06:10 +00:00
$headerType = mime_content_type($gameFileTmp);
$headerTypeMatch = array('application/zip');
if(in_array($headerType,$headerTypeMatch)){
2021-03-09 14:04:59 +00:00
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
if(empty($gameFileName)){
header("location: ../../../Frontend/index.php?error=emptyFile");
exit();
}
rename($gameFileTmp,"../../Games/".$gameFileNewName);
return $gameFileNewName;
2021-03-12 13:06:10 +00:00
}else{
header("location: location: ../../../Frontend/index.php?error=Wrong%20File%20Type");
2021-03-09 14:04:59 +00:00
}
2021-03-10 08:46:22 +00:00
return NULL;
}
/**
* @param string $thumbnailFileName
* @param string $thumbnailFileTmp
2021-03-12 13:06:10 +00:00
* @return string
2021-03-10 08:46:22 +00:00
*/
2021-03-12 13:06:10 +00:00
function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp){
2021-03-10 08:46:22 +00:00
$fileExtThumb = explode('.', $thumbnailFileName);
$fileActualExtThumb = strtolower(end($fileExtThumb));
2021-03-09 14:04:59 +00:00
2021-03-12 13:06:10 +00:00
$headerType = mime_content_type($thumbnailFileTmp);
$headerTypeMatch = array('image/png', 'image/jpeg','image/gif', 'image/svg+xml',);
2021-03-10 08:46:22 +00:00
2021-03-12 13:06:10 +00:00
if(in_array($headerType,$headerTypeMatch)){
2021-03-10 08:46:22 +00:00
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
if(empty($thumbnailFileName)){
header("location: ../../../Frontend/index.php?error=emptyFile");
exit();
}
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
return $thumbnailFileNewName;
2021-03-12 13:06:10 +00:00
}else{
header("location: location: ../../../Frontend/index.php?error=Wrong%20File%20Type");
2021-03-10 08:46:22 +00:00
}
return NULL;
2021-03-09 14:04:59 +00:00
}