Fixed error on images file ext

This commit is contained in:
neerholt
2021-03-10 09:46:22 +01:00
parent 527ab073ab
commit 053bf845cf
2 changed files with 42 additions and 45 deletions
+15 -38
View File
@@ -17,57 +17,34 @@ if(isset($_SESSION['token'])){
if(!isset($group->game_data_id)){
if(isset($_POST['submitUpload'])){
//Get the data from the user form
echo "tesz";
$gameFile = $_FILES['gameFile'];
$desc = $_POST['description'];
$title = $_POST['gameTitle'];
$thumbnail = $_FILES['thumbnailFile'];
$isWebBased = isset( $_POST['isWebBased']);
$gameFileName = $_FILES['gameFile']['name'];//Game name
$gameFileTmp = $_FILES['gameFile']['tmp_name'];//Tmp location of the file
$gameFileError = $_FILES['gameFile']['error'];//File error
//Handle data for thumbnail files
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
$thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error
$fileExtThumb = explode('.', $thumbnailFileName);
$fileActualExtThumb = strtolower(end($fileExtThumb));
$allowedFileTypeGame = array('zip');
$allowedFileTypeThumbnail = array('gif', 'jpeg', 'png', 'svg');
if(in_array($thumbnailFileName,$allowedFileTypeThumbnail)){
if( $thumbnailFileError === 0){
if(!empty($thumbnailFileName)){
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
$isImages = true;
}
$gameData = new GameData();
$gameData->game_name = $title;
$gameData->game_link = ZipFileHandler($gameFile);
$gameData->description = $desc;
if($isImages) $gameData->img = $thumbnailFileNewName;
$gameData->is_web_Based = $isWebBased;
$gameData->save();
$group->gameData()->associate($gameData);
$group->save();
if($isImages){
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
}
}
}else{
echo "Der var en fejl med at uploade din file";
if($thumbnailFileError === 0 && $gameFileError === 0){
$gameData = new GameData();
$gameData->game_name = $title;
$gameData->game_link = ZipFileHandler($gameFileName,$gameFileTmp);
$gameData->description = $desc;
if(isset($thumbnail)){
$gameData->img = imagesFileHandler($thumbnailFileName,$thumbnailFileTmp);
}
}else{
echo "Wrong file type";
$gameData->is_web_Based = $isWebBased;
$gameData->save();
$group->gameData()->associate($gameData);
$group->save();
}
}
}
}