images fix

This commit is contained in:
neerholt 2021-03-09 13:17:18 +01:00
parent 66eefe37a5
commit c880cbf48c
1 changed files with 14 additions and 3 deletions

View File

@ -2,6 +2,8 @@
require_once "../../../bootstrap.php";
use Backend\Models\GameData;
$isImages = false;
if(isset($_POST['submitUpload'])){
//Get the data from the user form
$gameFile = $_FILES['gameFile'];
@ -34,21 +36,30 @@ if(isset($_POST['submitUpload'])){
if(in_array($fileActualExtGame,$allowedFileTypeGame) || in_array($thumbnailFileName,$allowedFileTypeThumbnail)){
if($gameFileError === 0 || $thumbnailFileError === 0){
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
if(!empty($thumbnailFileName)){
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
$isImages = true;
}
if(empty($gameFileName)){
header("location: ../../../Frontend/index.php?error=emptyFile");
exit();
}else{
$gameData = new GameData();
$gameData->game_name = $title;
$gameData->game_link = $gameFileNewName;
$gameData->description = $desc;
$gameData->img = $thumbnailFileNewName;
if($isImages) $gameData->img = $thumbnailFileNewName;
$gameData->is_web_Based = $isWebBased;
$gameData->save();
rename($gameFileTmp,"../../Games/".$gameFileNewName);
rename($thumbnailFileTmp,"../../../Frontend/images/".$fileActualExtThumb);
if($isImages){
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
}
}
}else{
echo "Der var en fejl med at uploade din file";