Resolves file type.

@param  \Illuminate\Http\UploadedFile $file
@return string
500523
protected function resolveType(UploadedFile $file)
    {
        $extension = $file->clientExtension() ?: $file->extension();

        foreach ($this->knownExtensions() as $type => $extensions) {
            if (in_array($extension, $extensions)) {
                return ends_with($type, 's') ? substr($type, 0, -1) : $type;
            }
        }

        return 'file';
    }
297059
protected function generateSequenceName(UploadedFile $file)
    {
        $index = 1;
        $extension = $file->getClientOriginalExtension();
        $originalName = $file->getClientOriginalName();
        $newName = $originalName.'_'.$index.'.'.$extension;

        while ($this->storage->exists("{$this->getDirectory()}/$newName")) {
            $index++;
            $newName = $originalName.'_'.$index.'.'.$extension;
        }

        return $newName;
    }
869941
public function saveUploadedFile(UploadedFile $file)
    {
        do {
            $filename = Yii::$app->security->generateRandomString(16) . '.' . $file->getExtension();
            $path = $this->getTemporaryPath($filename);
        } while (is_file($path));

        if (!$file->saveAs($path)) {
            throw new ErrorException('Failed to save uploaded file');
        }

        return $filename;
    }
1005613
public static function getDataUriFromUploadedFile(UploadedFile $file)
    {
        return sprintf('data:%s;base64,%s', $file->getMimeType(), base64_encode(file_get_contents($file->getPathname())));
    }
490172
public function resolveClassname($file)
    {

        $splFile = new SplFileInfo($file);
        $parts   = explode('_', $splFile->getFilename());
        $strings = [];
        foreach ($parts as $part) {
            if (is_numeric($part)) {
                continue;
            }
            array_push($strings, $part);
        }
        $class = Str::studly(implode('_', $strings));
        return new $class;
    }
552113
public function getMimeTypeFromFile($file)
	{
		$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
		if (array_key_exists($extension, $this->_alt_mime_types)) {
			return $this->_alt_mime_types[$extension];
		} else {
			return (new \Finfo(FILEINFO_MIME_TYPE))->file($file);
		}
	}
653128
public function uploadOne(UploadedFile $file, $folder = null, $disk = 'public')
    {
        return $file->store($folder, ['disk' => $disk]);
    }
982497
public function resolve($file)
    {
        $class = Str::studly(implode('_', array_slice(explode('_', $file), 4)));

        return new $class($this->output);
    }
1174491
public function validate_upload(UploadedFile $file) {
		foreach ($this->restrictions as $k => $v) {
			switch ($k) {
				case 'maxsize':
					if ($v < $file->get_size()) {
						throw new Exception('Received file was too large.', Exception::ERR_BAD_REQUEST);
					}
					break;

				case 'mediatype':
					if (!in_array($file->get_mediatype(), $v)) {
						throw new Exception('Files with that extension are not allowed.', Exception::ERR_BAD_REQUEST);
					}
					break;

				case 'mimetype':
					if (!in_array($file->get_type(), $v)) {
						throw new Exception('Files with that extension are not allowed.', Exception::ERR_BAD_REQUEST);
					}
					break;

				case 'extension':
					if (!in_array($file->get_file_extension(), $v)) {
						throw new Exception('Files with that extension are not allowed.', Exception::ERR_BAD_REQUEST);
					}
					break;
			}
		}
		return true;
	}
1321333
private function getFileName(UploadedFile $file)
    {
        $extension = $file->getClientOriginalExtension();
        $fileName = str_replace('.' . $extension, '', $file->getClientOriginalName());

        $fileName = $fileName . '_' . md5(uniqid()) . '.' . $extension;

        return $fileName;
    }
4215
public function upload(UploadedFile $file)
    {
        self::$generic_file->moveUploadedFile(new File($file,
            $file->getClientOriginalName()), null, $this);

        return $this;
    }
807353
public function getUploadFileName(UploadedFile $file)
    {
        if (! is_callable($this->uploadFileName)) {
            return $this->defaultUploadFilename($file);
        }

        return call_user_func($this->uploadFileName, $file);
    }
1014310
protected static function getTypeFileExtList($file) {

		$info = pathinfo(strtolower($file));

		if(isset(self::$extensionToMime[$info['extension']])) {
			return self::$extensionToMime[$info['extension']];
		}
		else {
			return self::DEFAULT_MIME_TYPE;
		}

	}
689745
private function getFileToImport(UploadedFile $file, &$deleteFile)
    {
        $deleteFile = false;
        $post = $this->request->request;
        $dzuuid = $post->get('dzuuid');
        $dzIndex = $post->get('dzchunkindex');
        $dzTotalChunks = $post->get('dztotalchunkcount');
        if ($dzuuid !== null && $dzIndex !== null && $dzTotalChunks !== null) {
            $file->move($file->getPath(), $dzuuid . $dzIndex);
            if ($this->isFullChunkFilePresent($dzuuid, $file->getPath(), $dzTotalChunks)) {
                $deleteFile = true;

                return $this->combineFileChunks($dzuuid, $file->getPath(), $dzTotalChunks, $file);
            } else {
                return null;
            }
        } else {
            return $file;
        }
    }
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;
    }
792079
protected function getStoreName(UploadedFile $file)
    {
        if ($this->useUniqueName) {
            return $this->generateUniqueName($file);
        }

        if ($this->useSequenceName) {
            return $this->generateSequenceName($file);
        }

        if ($this->name instanceof \Closure) {
            return $this->name->call($this, $file);
        }

        if (is_string($this->name)) {
            return $this->name;
        }

        return $file->getClientOriginalName();
    }
433662
public static function createFromUploadedFile(UploadedFile $file)
    {
        $size = getimagesize($file->getRealPath());

        $image = new Image($file->guessExtension());
        $image->setOriginalFilename($file->getClientOriginalName());
        $image->setMimeType($file->getMimeType());
        $image->setSize(filesize($file->getRealPath()));
        $image->setWidth($size[0]);
        $image->setHeight($size[1]);

        return $image;
    }