2021-03-08 13:20:56 +00:00
|
|
|
<?php
|
2021-03-08 13:52:34 +00:00
|
|
|
require_once "../../../bootstrap.php";
|
2021-03-08 13:20:56 +00:00
|
|
|
use Backend\Models\GameData;
|
|
|
|
|
2021-03-09 12:17:18 +00:00
|
|
|
$isImages = false;
|
|
|
|
|
2021-03-09 12:30:21 +00:00
|
|
|
session_start();
|
|
|
|
|
|
|
|
if(isset($_SESSION['token'])){
|
|
|
|
|
2021-03-08 13:20:56 +00:00
|
|
|
if(isset($_POST['submitUpload'])){
|
|
|
|
//Get the data from the user form
|
|
|
|
$gameFile = $_FILES['gameFile'];
|
|
|
|
$desc = $_POST['description'];
|
|
|
|
$title = $_POST['gameTitle'];
|
2021-03-09 09:41:39 +00:00
|
|
|
$thumbnail = $_FILES['thumbnailFile'];
|
2021-03-08 13:52:34 +00:00
|
|
|
$isWebBased = isset( $_POST['isWebBased']);
|
2021-03-08 13:20:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
//Handle data for game files
|
|
|
|
$gameFileName = $_FILES['gameFile']['name'];//Game name
|
|
|
|
$gameFileTmp = $_FILES['gameFile']['tmp_name'];//Tmp location of the file
|
|
|
|
$gameFileError =$_FILES['gameFile']['error'];//File error
|
|
|
|
|
2021-03-09 09:41:39 +00:00
|
|
|
$fileExtGame = explode('.', $gameFileName);
|
|
|
|
$fileActualExtGame = strtolower(end($fileExtGame));
|
|
|
|
|
|
|
|
//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
|
2021-03-08 13:20:56 +00:00
|
|
|
|
2021-03-09 09:41:39 +00:00
|
|
|
$fileExtThumb = explode('.', $thumbnailFileName);
|
|
|
|
$fileActualExtThumb = strtolower(end($fileExtThumb));
|
2021-03-08 13:20:56 +00:00
|
|
|
|
|
|
|
|
2021-03-09 09:41:39 +00:00
|
|
|
$allowedFileTypeGame = array('zip');
|
|
|
|
$allowedFileTypeThumbnail = array('gif', 'jpeg', 'png', 'svg');
|
2021-03-08 13:20:56 +00:00
|
|
|
|
2021-03-09 09:41:39 +00:00
|
|
|
if(in_array($fileActualExtGame,$allowedFileTypeGame) || in_array($thumbnailFileName,$allowedFileTypeThumbnail)){
|
|
|
|
if($gameFileError === 0 || $thumbnailFileError === 0){
|
|
|
|
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
|
2021-03-09 12:17:18 +00:00
|
|
|
|
|
|
|
if(!empty($thumbnailFileName)){
|
|
|
|
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
|
|
|
|
$isImages = true;
|
|
|
|
}
|
|
|
|
|
2021-03-08 13:20:56 +00:00
|
|
|
if(empty($gameFileName)){
|
2021-03-08 13:52:34 +00:00
|
|
|
header("location: ../../../Frontend/index.php?error=emptyFile");
|
2021-03-08 13:20:56 +00:00
|
|
|
exit();
|
|
|
|
}else{
|
|
|
|
$gameData = new GameData();
|
|
|
|
$gameData->game_name = $title;
|
|
|
|
$gameData->game_link = $gameFileNewName;
|
2021-03-08 13:52:34 +00:00
|
|
|
$gameData->description = $desc;
|
2021-03-09 12:17:18 +00:00
|
|
|
if($isImages) $gameData->img = $thumbnailFileNewName;
|
2021-03-08 13:20:56 +00:00
|
|
|
$gameData->is_web_Based = $isWebBased;
|
|
|
|
$gameData->save();
|
|
|
|
|
2021-03-08 13:52:34 +00:00
|
|
|
rename($gameFileTmp,"../../Games/".$gameFileNewName);
|
2021-03-09 12:17:18 +00:00
|
|
|
if($isImages){
|
|
|
|
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
|
|
|
|
}
|
|
|
|
|
2021-03-08 13:20:56 +00:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
echo "Der var en fejl med at uploade din file";
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
echo "Wrong file type";
|
|
|
|
}
|
|
|
|
|
2021-03-09 12:30:21 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 13:20:56 +00:00
|
|
|
}
|