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

27 lines
837 B
PHP
Raw Normal View History

2021-03-09 14:04:59 +00:00
<?php
/**
* @param array $file
* @return string
*/
function ZipFileHandler(array $file){
$gameFileName = $file['gameFile']['name'];//Game name
$gameFileTmp = $file['gameFile']['tmp_name'];//Tmp location of the file
$gameFileError = $file['gameFile']['error'];//File error
$fileExtGame = explode('.', $gameFileName);
$fileActualExtGame = strtolower(end($fileExtGame));
$allowedFileTypeGame = array('zip');
if((in_array($fileActualExtGame,$allowedFileTypeGame))&&($gameFileError === 0)){
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
if(empty($gameFileName)){
header("location: ../../../Frontend/index.php?error=emptyFile");
exit();
}
rename($gameFileTmp,"../../Games/".$gameFileNewName);
return $gameFileNewName;
}
}