Fixed error on images file ext
This commit is contained in:
parent
527ab073ab
commit
053bf845cf
|
@ -1,19 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* @param array $file
|
||||
* @param string $gameFileName
|
||||
* @param string $gameFileTmp
|
||||
* @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
|
||||
|
||||
function ZipFileHandler(string $gameFileName, string $gameFileTmp){
|
||||
$fileExtGame = explode('.', $gameFileName);
|
||||
$fileActualExtGame = strtolower(end($fileExtGame));
|
||||
|
||||
$allowedFileTypeGame = array('zip');
|
||||
if((in_array($fileActualExtGame,$allowedFileTypeGame))&&($gameFileError === 0)){
|
||||
if(in_array($fileActualExtGame,$allowedFileTypeGame)){
|
||||
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
|
||||
if(empty($gameFileName)){
|
||||
header("location: ../../../Frontend/index.php?error=emptyFile");
|
||||
|
@ -22,6 +19,29 @@ function ZipFileHandler(array $file){
|
|||
rename($gameFileTmp,"../../Games/".$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($_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
|
||||
|
||||
//Handle data for thumbnail files
|
||||
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
|
||||
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
|
||||
$thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error
|
||||
|
||||
$fileExtThumb = explode('.', $thumbnailFileName);
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
if($thumbnailFileError === 0 && $gameFileError === 0){
|
||||
$gameData = new GameData();
|
||||
$gameData->game_name = $title;
|
||||
$gameData->game_link = ZipFileHandler($gameFile);
|
||||
$gameData->game_link = ZipFileHandler($gameFileName,$gameFileTmp);
|
||||
$gameData->description = $desc;
|
||||
if($isImages) $gameData->img = $thumbnailFileNewName;
|
||||
if(isset($thumbnail)){
|
||||
$gameData->img = imagesFileHandler($thumbnailFileName,$thumbnailFileTmp);
|
||||
}
|
||||
$gameData->is_web_Based = $isWebBased;
|
||||
$gameData->save();
|
||||
|
||||
$group->gameData()->associate($gameData);
|
||||
|
||||
$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