Game-Jaming/Backend/Controllers/upload.php

49 lines
1.4 KiB
PHP
Raw Normal View History

2021-03-08 13:20:56 +00:00
<?php
require_once "../../bootstrap.php";
use Backend\Models\GameData;
if(isset($_POST['submitUpload'])){
//Get the data from the user form
$gameFile = $_FILES['gameFile'];
$desc = $_POST['description'];
$title = $_POST['gameTitle'];
$isWebBased = $_POST['isWebBased'];
//Handle data for game files
$gameFileName = $_FILES['gameFile']['name'];//Game name
$gameFileTmp = $_FILES['gameFile']['tmp_name'];//Tmp location of the file
$gameFileType =$_FILES['gameFile']['type'];//File type
$gameFileError =$_FILES['gameFile']['error'];//File error
$fileExt = explode('.', $gameFileName);
$fileActualExt = strtolower(end($fileExt));
$allowedFileType = array('zip');
if(in_array($fileActualExt,$allowedFileType)){
if($gameFileError === 0){
$gameFileNewName = uniqid("", true). "." . $fileActualExt;
if(empty($gameFileName)){
header("location: ./index.php?error=emptyFile");
exit();
}else{
$gameData = new GameData();
$gameData->game_name = $title;
$gameData->game_link = $gameFileNewName;
$gameData->is_web_Based = $isWebBased;
$gameData->save();
rename($gameFileTmp,"../Games/".$gameFileNewName);
}
}else{
echo "Der var en fejl med at uploade din file";
}
}else{
echo "Wrong file type";
}
}