You can now upload zip filer

This commit is contained in:
neerholt 2021-03-08 14:20:56 +01:00
parent 9ab0526608
commit b242918038
6 changed files with 55 additions and 39 deletions

1
.gitignore vendored
View File

@ -107,3 +107,4 @@ fabric.properties
composer.phar composer.phar
/vendor/ /vendor/
/Backend/Database/test.db /Backend/Database/test.db
/Backend/Games/

View File

@ -0,0 +1,49 @@
<?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";
}
}

View File

@ -6,7 +6,7 @@ require "../bootstrap.php";
$gameJam = GameJam::firstOrCreate([ $gameJam = GameJam::firstOrCreate([
'name' => "First game jam ever!", 'startTime' => "2021-03-03T12:40", 'endTime' => "2021-04-03T12:40", 'description' => "Det her et en beskrivelse" 'name' => "First game jam ever!", 'start_time' => "2021-03-03T12:40", 'end_time' => "2021-04-03T12:40", 'description' => "Det her et en beskrivelse"
]); ]);
@ -17,7 +17,7 @@ $gameJam = GameJam::firstOrCreate([
<title>HTML Tutorial</title> <title>HTML Tutorial</title>
<body> <body>
<form action="SigningUp.php" method="POST"> <form action="Controllers/User/SigningUp.php" method="POST">
<input type="text" name="groupName" placeholder="Group name"> <input type="text" name="groupName" placeholder="Group name">
<input type="number" name="groupAmount" placeholder="Group Amount"> <input type="number" name="groupAmount" placeholder="Group Amount">
<input type="number" name="gameJamId" placeholder="Game Jam id"> <input type="number" name="gameJamId" placeholder="Game Jam id">
@ -26,7 +26,7 @@ $gameJam = GameJam::firstOrCreate([
</form> </form>
<form action="Login.php" method="POST"> <form action="Controllers/User/Login.php" method="POST">
<input type="text" name="groupName" placeholder="Group name"> <input type="text" name="groupName" placeholder="Group name">
<input type="password" name="password" placeholder="password"> <input type="password" name="password" placeholder="password">
<input type="submit" name="login" value="login"> <input type="submit" name="login" value="login">

View File

@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model as Eloquent;
class GameData extends Eloquent class GameData extends Eloquent
{ {
protected $fillable = [ protected $fillable = [
'game_link', 'is_web_Based', "img" 'game_name', 'game_link', 'is_web_Based', "img"
]; ];
public function group(){ public function group(){

View File

@ -17,7 +17,7 @@
<form action="../Backend/upload.php" method="POST" id="uploadGame" enctype="multipart/form-data"> <form action="../Backend/Controllers/upload.php" method="POST" id="uploadGame" enctype="multipart/form-data">
<input type="text" name="gameTitle" placeholder="Title på spillet"><br><br> <input type="text" name="gameTitle" placeholder="Title på spillet"><br><br>
@ -26,9 +26,6 @@
<label for="uploadGame">Upload spil [.zip]</label> <label for="uploadGame">Upload spil [.zip]</label>
<input type="file" name="gameFile" placeholder="Upload dit spil"><br><br> <input type="file" name="gameFile" placeholder="Upload dit spil"><br><br>
<label for="uploadGame">Upload thumbnail[png,jpg,gif]</label>
<input type="file" name="thumbnailFile" placeholder="Upload en thumbnail"><br><br>
<label for="web">Er spillet web based</label> <label for="web">Er spillet web based</label>
<input type="checkbox" id="web" name="isWebBased" value="true"><br><br> <input type="checkbox" id="web" name="isWebBased" value="true"><br><br>

View File

@ -1,31 +0,0 @@
<?php
if(isset($_POST['submitUpload'])){
//Get the data from the user form
$gameFile = $_FILES['gameFile'];
$thumbnailFile = $_FILES['thumbnailFile'];
$desc = $_POST['description'];
//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
//Handel data for thumbnail
$gameFileName = $_FILES['thumbnailFile']['name'];//Thumbnail name
$gameFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
$gameFileType =$_FILES['thumbnailFile']['type'];//File type
$fileExt = explode('.', $gameFileName);
$fileActualExt = strtolower(end($fileExt));
$fileDestination = '../images/';
move_uploaded_file($gameFileTmp,$fileDestination );
}