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

47 lines
1.5 KiB
PHP

<?php
/**
* @param string $gameFileName
* @param string $gameFileTmp
* @return string
*/
function ZipFileHandler(string $gameFileName, string $gameFileTmp){
$fileExtGame = explode('.', $gameFileName);
$fileActualExtGame = strtolower(end($fileExtGame));
$allowedFileTypeGame = array('zip');
if(in_array($fileActualExtGame,$allowedFileTypeGame)){
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
if(empty($gameFileName)){
header("location: ../../../Frontend/index.php?error=emptyFile");
exit();
}
rename($gameFileTmp,"../../Games/".$gameFileNewName);
return $gameFileNewName;
}
return NULL;
}
/**
* @param string $thumbnailFileName
* @param string $thumbnailFileTmp
* @return string
*/
function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp){
$fileExtThumb = explode('.', $thumbnailFileName);
$fileActualExtThumb = strtolower(end($fileExtThumb));
$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;
}