Fixed error on images file ext
This commit is contained in:
parent
527ab073ab
commit
053bf845cf
|
@ -1,19 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @param array $file
|
* @param string $gameFileName
|
||||||
|
* @param string $gameFileTmp
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function ZipFileHandler(array $file){
|
function ZipFileHandler(string $gameFileName, string $gameFileTmp){
|
||||||
$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);
|
$fileExtGame = explode('.', $gameFileName);
|
||||||
$fileActualExtGame = strtolower(end($fileExtGame));
|
$fileActualExtGame = strtolower(end($fileExtGame));
|
||||||
|
|
||||||
$allowedFileTypeGame = array('zip');
|
$allowedFileTypeGame = array('zip');
|
||||||
if((in_array($fileActualExtGame,$allowedFileTypeGame))&&($gameFileError === 0)){
|
if(in_array($fileActualExtGame,$allowedFileTypeGame)){
|
||||||
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
|
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
|
||||||
if(empty($gameFileName)){
|
if(empty($gameFileName)){
|
||||||
header("location: ../../../Frontend/index.php?error=emptyFile");
|
header("location: ../../../Frontend/index.php?error=emptyFile");
|
||||||
|
@ -22,6 +19,29 @@ function ZipFileHandler(array $file){
|
||||||
rename($gameFileTmp,"../../Games/".$gameFileNewName);
|
rename($gameFileTmp,"../../Games/".$gameFileNewName);
|
||||||
return $gameFileNewName;
|
return $gameFileNewName;
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $thumbnailFileName
|
||||||
|
* @param string $thumbnailFileTmp
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp){
|
||||||
|
|
||||||
|
$fileExtThumb = explode('.', $thumbnailFileName);
|
||||||
|
$fileActualExtThumb = strtolower(end($fileExtThumb));
|
||||||
|
|
||||||
|
$allowedFileTypeThumbnail = array('gif', 'jpeg', 'png', 'svg');
|
||||||
|
|
||||||
|
if(in_array($fileActualExtThumb,$allowedFileTypeThumbnail)){
|
||||||
|
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
|
||||||
|
if(empty($thumbnailFileName)){
|
||||||
|
header("location: ../../../Frontend/index.php?error=emptyFile");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
|
||||||
|
return $thumbnailFileNewName;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
|
@ -17,57 +17,34 @@ if(isset($_SESSION['token'])){
|
||||||
if(!isset($group->game_data_id)){
|
if(!isset($group->game_data_id)){
|
||||||
if(isset($_POST['submitUpload'])){
|
if(isset($_POST['submitUpload'])){
|
||||||
//Get the data from the user form
|
//Get the data from the user form
|
||||||
|
echo "tesz";
|
||||||
$gameFile = $_FILES['gameFile'];
|
$gameFile = $_FILES['gameFile'];
|
||||||
$desc = $_POST['description'];
|
$desc = $_POST['description'];
|
||||||
$title = $_POST['gameTitle'];
|
$title = $_POST['gameTitle'];
|
||||||
$thumbnail = $_FILES['thumbnailFile'];
|
$thumbnail = $_FILES['thumbnailFile'];
|
||||||
$isWebBased = isset( $_POST['isWebBased']);
|
$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
|
||||||
|
|
||||||
//Handle data for thumbnail files
|
|
||||||
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
|
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
|
||||||
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
|
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
|
||||||
$thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error
|
$thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error
|
||||||
|
|
||||||
$fileExtThumb = explode('.', $thumbnailFileName);
|
if($thumbnailFileError === 0 && $gameFileError === 0){
|
||||||
$fileActualExtThumb = strtolower(end($fileExtThumb));
|
|
||||||
|
|
||||||
|
|
||||||
$allowedFileTypeGame = array('zip');
|
|
||||||
$allowedFileTypeThumbnail = array('gif', 'jpeg', 'png', 'svg');
|
|
||||||
|
|
||||||
if(in_array($thumbnailFileName,$allowedFileTypeThumbnail)){
|
|
||||||
if( $thumbnailFileError === 0){
|
|
||||||
|
|
||||||
if(!empty($thumbnailFileName)){
|
|
||||||
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
|
|
||||||
$isImages = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$gameData = new GameData();
|
$gameData = new GameData();
|
||||||
$gameData->game_name = $title;
|
$gameData->game_name = $title;
|
||||||
$gameData->game_link = ZipFileHandler($gameFile);
|
$gameData->game_link = ZipFileHandler($gameFileName,$gameFileTmp);
|
||||||
$gameData->description = $desc;
|
$gameData->description = $desc;
|
||||||
if($isImages) $gameData->img = $thumbnailFileNewName;
|
if(isset($thumbnail)){
|
||||||
|
$gameData->img = imagesFileHandler($thumbnailFileName,$thumbnailFileTmp);
|
||||||
|
}
|
||||||
$gameData->is_web_Based = $isWebBased;
|
$gameData->is_web_Based = $isWebBased;
|
||||||
$gameData->save();
|
$gameData->save();
|
||||||
|
|
||||||
$group->gameData()->associate($gameData);
|
$group->gameData()->associate($gameData);
|
||||||
|
|
||||||
$group->save();
|
$group->save();
|
||||||
|
|
||||||
if($isImages){
|
|
||||||
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
echo "Der var en fejl med at uploade din file";
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
echo "Wrong file type";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue