HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers33/bbec.nl/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();
    }

}