Returns moved file.

@param  \Illuminate\Http\UploadedFile $file
@param  string $type
@param  array $attributes
@return \App\Media\MediaInterface
327005
protected function submit(UploadedFile $file, $type, array $attributes)
    {
        switch ($type) {
            case 'image':
                return (new \Routegroup\Media\Upload\Image)->make($file, $attributes);

            case 'audio':
                return (new \Routegroup\Media\Upload\Audio)->make($file, $attributes);

            case 'video':
                return (new \Routegroup\Media\Upload\Video)->make($file, $attributes);

            case 'archive':
                return (new \Routegroup\Media\Upload\Archive)->make($file, $attributes);

            default:
                return (new \Routegroup\Media\Upload\File)->make($file, $attributes);
        }
    }
1064552
public function uploadImage(UploadedFile $file)
    {
        $image = $this
            ->imageManager
            ->createImage($file);

        $this
            ->mediaEventDispatcher
            ->dispatchImagePreUploadEvent($image);

        $this->imageObjectManager->persist($image);
        $this->imageObjectManager->flush($image);

        $this->fileManager->uploadFile(
            $image,
            file_get_contents($file->getRealPath()),
            true
        );

        $this
            ->mediaEventDispatcher
            ->dispatchImageOnUploadEvent($image);

        return $image;
    }
1204442
final protected function createImageFromFile($file, $type)
    {
        switch ($type) {
            case \IMAGETYPE_GIF:
                return imagecreatefromgif($file);

            case \IMAGETYPE_JPEG:
                return imagecreatefromjpeg($file);

            case \IMAGETYPE_PNG:
                return imagecreatefrompng($file);
    
            default:
                throw new LogicException(sprintf('Can not create image from "%s"', $file));
        }
    }
1310814
protected function buildMedia(string $type, $files, array $attributes): string
	{
		$sources = '';

		foreach((array) $files as $file)
		{
			$sources .= $this->tag('source', ['src' => $file]);
		}

		return $this->tag($type, $attributes, $sources);
	}
111483
public function appendFile($src, $type = null, array $attributes = array(), $onTop = false)
    {
        static $counter = 0;
        
        $attributes['src'] = $src;
        $type !== null && $attributes['type'] = $type;
        $this->files[$onTop == 'high' ? $counter : $counter + 1000] = Html::buildHtmlElement('script', $attributes, '');
        $counter++;
        return $this;
    }
885256
private function uploadFile(UploadedFile $file)
    {
        /** @var FileStorage $fileStorage */
        $fileStorage = Yii::$app->get('fileStorage');

        $filename = $fileStorage->saveUploadedFile($file);

        return $fileStorage->put($filename, $file->name);
    }
824502
private function uploadOne(UploadedFile $file)
    {
        try {
            $validator = new FileValidator([$this->_config]);
            if ($validator->validate($file, $error)) {
                $fileInfo = $file->save();
                $result = [
                    'name' => Html::encode($fileInfo->filename),
                    'url' => $fileInfo->getUrl(),
                    'path' => $fileInfo->path,
                    'extension' => $file->extension,
                    'type' => $fileInfo->type,
                    'size' => $fileInfo->size
                ];
                if ($this->onlyImage !== true) {
                    $result['filename'] = $result['name'];
                }
            } else {
                $result = [
                    'error' => $error
                ];
            }
        } catch (Exception $e) {
            $result = [
                'error' => $e->getMessage()
            ];
        }
        return $result;
    }
653128
public function uploadOne(UploadedFile $file, $folder = null, $disk = 'public')
    {
        return $file->store($folder, ['disk' => $disk]);
    }
1126597
public function handleUploadedFile(UploadedFile $file)
    {
        if ($file->getClientOriginalExtension() === 'zip') {
            $tempFolder = $this->extractZip($file);
            $counters = array('new' => 0, 'updated' => 0);
            foreach (scandir($tempFolder) as $path) {
                if (is_file($tempFolder.'/'.$path)) {
                    $fileCounters = $this->importFile($tempFolder.'/'.$path);
                    $counters['new'] += $fileCounters['new'];
                    $counters['updated'] += $fileCounters['updated'];
                }
            }
            unset($tempFolder);
        } else {
            $counters = $this->importFile($file->getRealPath(), $file->getClientOriginalName());
        }

        return $counters;
    }
706170
protected function createUploadedFile($file)
	{
		try {
			$imageManager = new ImageManager;
			$image = $imageManager->make($file);
			$extension = $this->getExtensionFromMime($image->mime());
			$fileName = $this->generateFileName($extension);
			$temporaryPath = $this->getTemporaryImageBasePath();
			$this->temporaryImage = $temporaryPath.'/'.$fileName;
			$image->save($this->temporaryImage);

			return new UploadedFile(
				$this->temporaryImage,
				$fileName, 
				$image->mime(),
				$image->filesize(),
				null,
				TRUE
			);
		} catch (Exception $e) {
			throw new ImageUploaderException("Error create uploaded file");
		}
	}
729500
protected function uploadAndDeleteOriginal(UploadedFile $file)
    {
        $this->renameIfExists($file);

        $path = $this->storage->putFileAs($this->getDirectory(), $file, $this->name);

        $this->destroy();

        return $path;
    }
821031
public function fileDownload($file)
    {
        $response = new SymfonyResponse();

        $response->headers->set('Content-Disposition', 
            $response->headers->makeDisposition(
                ResponseHeaderBag::DISPOSITION_ATTACHMENT,
                $file
            )
        );

        return $response;
    }
457680
public function resize(UploadedFile $file, $style)
    {
        $quality = $this->option('quality', 90);

        $this->imagine = new $this->image_processor;

        $file_path = @tempnam(sys_get_temp_dir(), 'STP') . '.' . $file->getClientOriginalName();
        list($width, $height, $option, $enlarge) = $this->parseStyleDimensions($style);
        $method = 'resize' . ucfirst($option);

        if ($method == 'resizeCustom') {
            $this->resizeCustom($file, $style, $enlarge)
                ->save($file_path, [
                    'quality' => $quality,
                ]);

            return $file_path;
        }

        $image = $this->imagine->open($file->getRealPath());

        // Orient the file programmatically
        if ($this->option('auto_orient', false)) {
            $image = $this->autoOrient($file->getRealPath(), $image);
        }

        // Force a color palette
        if ($palette = $this->option('color_palette')) {
            $image->usePalette(new $palette);
        }

        $this->$method($image, $width, $height, $enlarge)
            ->save($file_path, [
                'quality' => $quality,
                'flatten' => false,
            ]);

        return $file_path;
    }
1338231
protected function convertFileInformation($file)
    {
        if ($file instanceof UploadedFile) {
            return $file;
        }

        $file = $this->fixPhpFilesArray($file);
        if (\is_array($file)) {
            $keys = array_keys($file);
            sort($keys);

            if ($keys == self::$fileKeys) {
                if (UPLOAD_ERR_NO_FILE == $file['error']) {
                    $file = null;
                } else {
                    $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['error']);
                }
            } else {
                $file = array_map([$this, 'convertFileInformation'], $file);
                if (array_keys($keys) === $keys) {
                    $file = array_filter($file);
                }
            }
        }

        return $file;
    }
482338
public function install($type, array $attributes)
    {
        $extension       = new Extension;
        $extension->type = $type;
        $extension->name = $attributes['name'];
        if (isset($attributes['parameters'])) {
            $extension->parameters = $attributes['parameters'];
        }
        $extension->manifest = json_encode($attributes);
        $extension->save();

        return $extension;
    }
998445
private function uploadOne(UploadedFile $file)
    {
        try {
            $uploader = new Uploader(['config' => $this->_config]);
            $uploader->up($file);
            $fileInfo = $uploader->getFileInfo();
            $result = [
                'name' => Html::encode($file->name),
                'url' => $fileInfo['url'],
                'path' => $fileInfo['url'],
                'extension' => $file->extension,
                'type' => $file->type,
                'size' => $file->size
            ];
            if ($this->onlyImage !== true) {
                $result['filename'] = $result['name'];
            }

        } catch (Exception $e) {
            $result = [
                'error' => $e->getMessage()
            ];
        }
        return $result;
    }
49560
public static function file(string $name, array $attributes = null) : string
    {
        // Set the input type
        $attributes['type'] = 'file';

        return Form::input($name, '', $attributes);
    }