Upload file on server

@param UploadedFile|null $file

@return string
430238
public function upload(UploadedFile $file = null)
    {
        if ($file === null) {
            return '';
        }

        $fileName = $this->getFileName($file);
        $file->move($this->getTargetDir(), $fileName);

        return $fileName;
    }
1306625
public function moveUpload(UploadedFile $file) {

        // Nest the uploaded file into unique sub directory and a unqiue name
        $path = $this->makeNestedAndUniquePath($file->getClientOriginalName());

        // Move the uploaded file to the destination using Flysystem and return
        // the new path
        $this->manager->move('tmp://'.$file->getFilename(), 'disk://'.$path);

        // Return the URL of the upload.
        return $this->helpers->url($path);
    }
1019637
public static function createFromUploadedFile(UploadedFile $file = null)
    {
        if (!$file instanceof UploadedFile) {
            return;
        }

        $instance = new static();

        self::$generic_file->moveUploadedFile(new File($file,
            $file->getClientOriginalName()), null, $instance);

        return $instance;
    }
1304327
public function store(UploadFile $file, $location = null, array $option = [])
    {
        if (is_array($location)) {
            $option = $location;
            $location = null;
        }

        if (isset($option['as'])) {
            $filename = $option['as'];
        } else {
            $filename = $file->getHashName();
        }

        if (is_null($location)) {
            $location = $filename;
        } else {
            $location = trim($location, '/') . '/' . $filename;
        }

        return $this->put($location, $file->getContent());
    }
684074
public function getFileParams (UploadedFile $file)
    {
        $params = [];

        if ($this->resourceID)
            $params['id'] = $this->resourceID;
        else
            $params['id'] = Uuid::uuid4 ()->toString ();

        $params['original_name'] = $file->getClientOriginalName ();
        $params['extension']     = '.' . $file->getClientOriginalExtension ();
        $params['path']          = $this->uploadPath . $params['id'] . $params['extension'];
        $params['size']          = $file->getClientSize ();
        $params['mime_type']     = $file->getClientMimeType ();

        return $params;
    }
958549
protected function upload(UploadedFile $file): array
    {
        $media = new Media();
        $media->bucket = Yii::$app->request->get('bucket');
        $media->setDynamicFileRules($this->rules);
        $result = $media->linkMedia($file, $this->model::className(), $this->model->getPrimaryKey());
        if (is_object($result)) {
            return [
                'status' => 'success',
                'name' => $file->name,
                'mediaId' => $result->id,
                'media' => $result,
            ];
        } else {
            return [
                'status' => 'error',
                'message' => $result,
            ];
        }
    }
539160
public static function createFromUploadedFile(UploadedFile $file)
    {
        $asset = new Asset();
        $guesser = MimeTypeGuesser::getInstance();
        return $asset
            ->setFilename($file->getFilename())
            ->setExtension($file->getExtension())
            ->setPathname($file->getPathname())
            ->setMimeType($guesser->guess($file->getPathname()))
            ->setClientOriginalName($file->getClientOriginalName())
            ->setClientOriginalExtension($file->getClientOriginalExtension())
            ->setClientMimeType($file->getClientMimeType())
        ;
    }
1147268
public function handleSingleFile($file)
    {
        if (!$file instanceof UploadedFile) {
            throw new \Exception("Dados inválidos para upload");
        }

        $document = $this->createDocument($file);

        $this->processBeforeSave($document);

        $disk = Storage::disk()->getDriver();
        $disk->put($document->filePath, fopen($file, 'r+'), [
            'visibility' => 'public',
            'ContentType' => $document->mimeType
        ]);

        $document->url = config('filesystems.default') == 'public' ? asset('images/' . $document->filePath) : Storage::url($document->filePath);
        $document->save();

        $this->addFileToList($document);

        return $document;
    }
867555
protected function getUploadedFilename(UploadedFile $file): string
    {
        $extension = $file->getClientOriginalExtension();

        return \sprintf('%s.%s', Str::random(10), $extension);
    }
499953
public function file(UploadedFile $file)
	{
		$this->file = $file;
		$this->filename = $file->getClientOriginalName();
		$this->sanitizeFilename();

		return $this;
	}
145125
public function getUploadPath(UploadedFile $file)
    {
        if (($path = $this->uploadPath)) {
            if (is_callable($path)) {
                $path = call_user_func($path, $file);
            }

            return trim($path, '/');
        }

        return $this->getDefaultUploadPath($file);
    }
1321333
private function getFileName(UploadedFile $file)
    {
        $extension = $file->getClientOriginalExtension();
        $fileName = str_replace('.' . $extension, '', $file->getClientOriginalName());

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

        return $fileName;
    }
653128
public function uploadOne(UploadedFile $file, $folder = null, $disk = 'public')
    {
        return $file->store($folder, ['disk' => $disk]);
    }
221162
protected function handleUniqueFile($file)
    {
        $uploadedFile = null;

        //The current file was uploaded successfully?
        if (!$file['error']) {
            $uploadedFile = new UploadedFile(
                $file['tmp_name'],
                $file['name'],
                $file['type']
            );
        }

        return $uploadedFile;
    }
1363313
private function resolveFilename($file)
    {
        if (empty($file)) {
            return null;
        }

        if (
            ($file instanceof UploadedFileInterface && $file->getError() === 0)
            || $file instanceof StreamableInterface
        ) {
            return StreamWrapper::getFilename($file->getStream());
        }

        if (is_array($file)) {
            if (!isset($file['tmp_name'])) {
                return null;
            }

            $file = $file['tmp_name'];
        }

        if (!is_string($file) || !$this->files->exists($file)) {
            return null;
        }

        return $file;
    }
1055252
protected function upload(UploadedFile $file)
    {
        $this->renameIfExists($file);

        return $this->storage->putFileAs($this->getDirectory(), $file, $this->name);
    }
1065410
public function uploadAvatar(string $file): Response
    {
        $this->requiresAccessToken();

        return $this->stream(
            'POST', 'profile/avatar', $this->getApiHeaders(), $this->getApiBody(), compact('file')
        );
    }