File: D:/HostingSpaces/EUmans/umansradepo.be/workbench/komma/kms/src/Komma/Kms/Images/ImageController.php
<?php
/**
* Short description for the file.
*
* @author Komma <support@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
namespace Komma\Kms\Images;
use Komma\Kms\Files\FileService;
use Komma\Kms\Images\Models\Image;
class ImageController extends \BaseController
{
private $imageService;
private $fileService;
public function __construct(ImageService $imageService, FileService $fileService)
{
$this->imageService = $imageService;
$this->fileService = $fileService;
}
public function upload()
{
//Set subFolder
if(\Input::has('subFolder')) $this->imageService->setUp('subfolder', \Input::get('subFolder'));
//Set attributeKey
if(\Input::has('attribute_key')) $this->imageService->setUp('attribute_key',\Input::get('attribute_key'));
$uploadSizes = [];
//Get the uploadSizes
if(\Input::has('uploadSizes') && is_array(\Input::get('uploadSizes')))$uploadSizes = \Input::get('uploadSizes');
$dynamic = false;
//Get if is dynamic
if(\Input::has('dynamic'))$dynamic =(\Input::get('dynamic') == 'true'?true:false);
if(\Input::file('file')->getMimeType()=='image/gif'){
if(\Input::has('attribute_key')){
$attribute_key = \Input::get('attribute_key');
}
else{
$attribute_key = 'images';
}
$file = \Input::file('file');
$file->tmpName = 'file';
if(!$result = $this->fileService->upload([$file], \Input::get('subFolder'))) return null;
if($dynamic) return $this->imageService->saveGifToDatabase($result[0], $attribute_key, true)->toJson();
return $this->imageService->saveGifToDatabase($result[0], $attribute_key)->toJson();
}
//upload the files to the server
if (!$result = $this->imageService->uploadImages([\Input::file('file')],$uploadSizes,$dynamic)) return null;
//Save image to database
$image = $this->imageService->saveImageToDatabase($result[0]);
return $image->toJson();
}
}