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

47 lines
1.5 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-09 14:04:59 +00:00
* @return string
*/
2021-03-10 08:46:22 +00:00
function ZipFileHandler(string $gameFileName, string $gameFileTmp){
2021-03-09 14:04:59 +00:00
$fileExtGame = explode('.', $gameFileName);
$fileActualExtGame = strtolower(end($fileExtGame));
$allowedFileTypeGame = array('zip');
2021-03-10 08:46:22 +00:00
if(in_array($fileActualExtGame,$allowedFileTypeGame)){
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-10 08:46:22 +00:00
return NULL;
}
/**
* @param string $thumbnailFileName
* @param string $thumbnailFileTmp
* @return string
*/
function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp){
2021-03-09 14:04:59 +00:00
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-10 08:46:22 +00:00
$allowedFileTypeThumbnail = array('gif', 'jpeg', 'png', 'svg');
if(in_array($fileActualExtThumb,$allowedFileTypeThumbnail)){
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
if(empty($thumbnailFileName)){
header("location: ../../../Frontend/index.php?error=emptyFile");
exit();
}
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
return $thumbnailFileNewName;
}
return NULL;
2021-03-09 14:04:59 +00:00
}