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

53 lines
1.8 KiB
PHP

<?php
/**
* @param string $gameFileName
* @param string $gameFileTmp
* @return string
*/
function ZipFileHandler(string $gameFileName, string $gameFileTmp){
$fileExtGame = explode('.', $gameFileName);
$fileActualExtGame = strtolower(end($fileExtGame));
$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.html?error=emptyFile");
exit();
}
rename($gameFileTmp,"../../Games/".$gameFileNewName);
return $gameFileNewName;
}else{
header("location: location: ../../../Frontend/index.html?error=Wrong%20File%20Type");
}
return NULL;
}
/**
* @param string $thumbnailFileName
* @param string $thumbnailFileTmp
* @return string
*/
function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp){
$fileExtThumb = explode('.', $thumbnailFileName);
$fileActualExtThumb = strtolower(end($fileExtThumb));
$headerType = mime_content_type($thumbnailFileTmp);
$headerTypeMatch = array('image/png', 'image/jpeg','image/gif', 'image/svg+xml',);
if(in_array($headerType,$headerTypeMatch)){
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
if(empty($thumbnailFileName)){
header("location: ../../../Frontend/index.html?error=emptyFile");
exit();
}
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
return $thumbnailFileNewName;
}else{
header("location: location: ../../../Frontend/index.html?error=Wrong%20File%20Type");
}
return NULL;
}