Move document to /uploads/documents
@param UploadedFile $file
@param              $documentable
@return \Illuminate\Http\JsonResponse|static
778735
private function moveAndCreateDocument(UploadedFile $file, $documentable)
    {
        $name = token();
        $extension = '.' . $file->extension();
        $filename = $name . $extension;

        $file->move(upload_path('documents'), $filename);

        // file not moved
        if (!\File::exists(upload_path('documents') . $filename)) {
            return false;
        }

        $originalName = $file->getClientOriginalName();
        $originalName = substr($originalName, 0, strpos($originalName, $extension));
        $name = strlen($originalName) <= 2 ? $documentable->name : $originalName;
        $photo = Document::create([
            'filename'          => $filename,
            'documentable_id'   => $documentable->id,
            'documentable_type' => get_class($documentable),
            'name'              => strlen($name) < 2 ? 'Document Name' : $name,
        ]);

        return $photo;
    }
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())
        ;
    }
430238
public function upload(UploadedFile $file = null)
    {
        if ($file === null) {
            return '';
        }

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

        return $fileName;
    }
753489
public SendDocument setDocument(File file) {
        Objects.requireNonNull(file, "documentName cannot be null!");
        this.document = new InputFile(file, file.getName());
        return this;
    }
1048351
public function addFile($file, $writeable = false): ConfigCollection {
        $config = FileConfig::load($file, $writeable);
        if ($config) {
            $this->addConfig($config);
        }
        return $this;
    }
157625
public function setDocumentFile(File $documentFile = null)
    {
        $this->documentFile = $documentFile;

        if ($documentFile) {
            // It is required that at least one field changes if you are using doctrine
            // otherwise the event listeners won't be called and the file is lost
            $this->modified = new \DateTimeImmutable();
        }

        return $this;
    }
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,
            ];
        }
    }
972496
public function uploadFile(File $file, $raw_file)
    {
        $result = new Result();

        if (file_exists($raw_file)) {
            return $this->uploadFileFromFilesystem($file, $raw_file);
        }

        return $result;
    }
1348543
public function saveFile(UploadedFile $file)
    {
        Validator::validate(
            [$this->getName() => $file],
            $this->getUploadValidationRules(),
            $this->getUploadValidationMessages(),
            $this->getUploadValidationTitles()
        );

        $path = $file->storeAs(
            $this->getUploadPath($file),
            $this->getUploadFileName($file),
            $this->getDisk()
        );

        return $this->getFileInfo($path);
    }
803857
protected function prepareForeach(UploadedFile $file = null)
    {
        $this->name = $this->getStoreName($file);

        return tap($this->upload($file), function () {
            $this->name = null;
        });
    }
272218
public function setFile(UploadedFile $file = null)
    {
        $this->file = $file;

        if (null === $this->getFile()) {
            return null;
        }

        // check if we have an old image path
        if (isset($this->path)) {
            // store the old name to delete after the update
            $this->temp = $this->path;
            $this->path = null;
        } else {
            $this->path = 'initial';
        }

        return $this;
    }
1077925
public function setUploadedFile(StorableFileInterface $file)
    {
        $this->instance->markAttachmentUpdated();

        if ( ! $this->config->keepOldFiles()) {
            $this->clear();
        }

        $this->clearTarget();

        $this->uploadedFile = $file;

        // Update the model instance with appropriate column values
        $this->instanceWrite('file_name', $this->uploadedFile->name());
        $this->instanceWrite('file_size', $this->uploadedFile->size());
        $this->instanceWrite('content_type', $this->uploadedFile->mimeType());
        $this->instanceWrite('updated_at', Carbon::now());

        $this->performCallableHookBeforeProcessing();

        $this->queueAllForWrite();
    }
624395
public function move(string $directory, string $filename='')
  {
    # If no filename is provided, assume the incoming name
    if (empty($filename)) $this->setFilename( $this->getName() );

    # Move the file
    $ok = \move_uploaded_file($this->getTmpName(), $destination . DIRECTORY_SEPARATOR . $filename );

    # Set property
    $this->setIsMoved($ok);

    return $ok;
  }
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");
		}
	}
1347867
private function createModel(UploadedFile $file, Request $request)
    {
        $model = app()->make(File::class, [
            'file'  => $file,
            'disk'  => $request->get('storage', 'public'),
            'group' => $request->get('group'),
        ])->load();

        $model->url = $model->url();

        return $model;
    }
181551
public function addPostFile($filename)
    {
        if ($filename instanceof UploadedFile) {

            // Get original filename
            $name = $filename->getClientOriginalName();

            // Move the file
            $file = $filename->move(sys_get_temp_dir() . '/' . uniqid(), $name);

            // Get the new file path
            $filename = $file->getRealPath();
        }

        if (!is_readable($filename)) {
            throw new InvalidArgumentException("Unable to open {$filename} for reading");
        }

        // PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax
        // See: https://wiki.php.net/rfc/curl-file-upload
        if (function_exists('curl_file_create')) {
            return curl_file_create($filename);
        }

        // Use the old style if using an older version of PHP
        return "@{$filename}";
    }
226035
public function handleUploadedFiles(UploadedFile $file, $extension, $dir)
    {
        $original_file = $file->getClientOriginalName();
        $path_parts = pathinfo($original_file);

        $increment = '';
        while (file_exists($dir . FileManager::DS . $path_parts['filename'] . $increment . '.' . $extension)) {
            $increment++;
        }

        $basename = $path_parts['filename'] . $increment . '.' . $extension;
        $file->move($dir, $basename);
    }