57 lines
1.7 KiB
PHP
57 lines
1.7 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)){
|
|
http_response_code(400);
|
|
exit();
|
|
}
|
|
rename($gameFileTmp,"../../Games/".$gameFileNewName);
|
|
return $gameFileNewName;
|
|
}else{
|
|
http_response_code(400);
|
|
echo json_encode(["message" => "Wrong file type gameFile"]);
|
|
exit();
|
|
}
|
|
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)){
|
|
http_response_code(400);
|
|
exit();
|
|
}
|
|
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
|
|
return $thumbnailFileNewName;
|
|
}else{
|
|
http_response_code(400);
|
|
echo json_encode(["message" => "Wrong file type thumbnailFile"]);
|
|
exit();
|
|
}
|
|
return NULL;
|
|
} |