new fille handler
This commit is contained in:
parent
a69890c970
commit
527ab073ab
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
/**
|
||||
* @param array $file
|
||||
* @return string
|
||||
*/
|
||||
|
||||
function ZipFileHandler(array $file){
|
||||
$gameFileName = $file['gameFile']['name'];//Game name
|
||||
$gameFileTmp = $file['gameFile']['tmp_name'];//Tmp location of the file
|
||||
$gameFileError = $file['gameFile']['error'];//File error
|
||||
|
||||
$fileExtGame = explode('.', $gameFileName);
|
||||
$fileActualExtGame = strtolower(end($fileExtGame));
|
||||
|
||||
$allowedFileTypeGame = array('zip');
|
||||
if((in_array($fileActualExtGame,$allowedFileTypeGame))&&($gameFileError === 0)){
|
||||
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
|
||||
if(empty($gameFileName)){
|
||||
header("location: ../../../Frontend/index.php?error=emptyFile");
|
||||
exit();
|
||||
}
|
||||
rename($gameFileTmp,"../../Games/".$gameFileNewName);
|
||||
return $gameFileNewName;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
require_once "../../../bootstrap.php";
|
||||
require_once('../Group/Group.php');
|
||||
require_once('FileHandler.php');
|
||||
use Backend\Models\GameData;
|
||||
|
||||
use Backend\Models\Group;
|
||||
|
@ -23,14 +24,6 @@ if(isset($_SESSION['token'])){
|
|||
$isWebBased = isset( $_POST['isWebBased']);
|
||||
|
||||
|
||||
//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
|
||||
|
||||
$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
|
||||
|
@ -43,22 +36,18 @@ if(isset($_SESSION['token'])){
|
|||
$allowedFileTypeGame = array('zip');
|
||||
$allowedFileTypeThumbnail = array('gif', 'jpeg', 'png', 'svg');
|
||||
|
||||
if(in_array($fileActualExtGame,$allowedFileTypeGame) || in_array($thumbnailFileName,$allowedFileTypeThumbnail)){
|
||||
if($gameFileError === 0 || $thumbnailFileError === 0){
|
||||
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
|
||||
if(in_array($thumbnailFileName,$allowedFileTypeThumbnail)){
|
||||
if( $thumbnailFileError === 0){
|
||||
|
||||
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->game_link = ZipFileHandler($gameFile);
|
||||
$gameData->description = $desc;
|
||||
if($isImages) $gameData->img = $thumbnailFileNewName;
|
||||
$gameData->is_web_Based = $isWebBased;
|
||||
|
@ -68,11 +57,9 @@ if(isset($_SESSION['token'])){
|
|||
|
||||
$group->save();
|
||||
|
||||
rename($gameFileTmp,"../../Games/".$gameFileNewName);
|
||||
if($isImages){
|
||||
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
echo "Der var en fejl med at uploade din file";
|
||||
|
|
Loading…
Reference in New Issue