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

50 lines
1.8 KiB
PHP

<?php
require_once "../../../bootstrap.php";
require_once('../Group/Group.php');
require_once('FileHandler.php');
use Backend\Models\GameData;
use Backend\Models\Group;
$isImages = false;
session_start();
if(isset($_SESSION['token'])){
$group = groupViaToken($_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
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
$thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error
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);
}
$gameData->is_web_Based = $isWebBased;
$gameData->save();
$group->gameData()->associate($gameData);
$group->save();
}
}
}
}