Store uploaded file by configured path pattern and fill data to this model.

@param Symfony\Component\HttpFoundation\File\UploadedFile $file

@return Illuminate\Database\Eloquent\Model
4215
public function upload(UploadedFile $file)
    {
        self::$generic_file->moveUploadedFile(new File($file,
            $file->getClientOriginalName()), null, $this);

        return $this;
    }
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';
    }
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);
    }
885256
private function uploadFile(UploadedFile $file)
    {
        /** @var FileStorage $fileStorage */
        $fileStorage = Yii::$app->get('fileStorage');

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

        return $fileStorage->put($filename, $file->name);
    }
808384
public function store()
    {
        try {
            $request = app(FileStoreRequest::class);
            $this->model->manageUpload($request->file('file'), $request->except('file'));
            return redirect()->route('admin.files.index')->withStatus(__('msg.uploaded_success'));
        } catch (ValidationException $e) {
            $message = $e->validator->errors()->first();
            return redirect()->back()->withInput()->withErrors($message);
        } catch (\Exception $e) {
            $message = 'owner' == user('role') ? $e->getMessage() : __('validation.uploaded');
            return redirect()->back()->withInput()->withErrors($message);
        }
    }
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;
    }
430238
public function upload(UploadedFile $file = null)
    {
        if ($file === null) {
            return '';
        }

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

        return $fileName;
    }
1157222
public function setFile($file)
    {

        //Return false if file does not exists;
        if (!$this->isFile($file)) {
            return false;
        }
        //Get the file info
        $this->file = $file;
        $this->pathinfo[$file] = pathinfo($file);

        //Return an instance of the file object;
        return $this;
    }
153633
protected function saveResourceInStorage (HCResources $resource, UploadedFile $file)
    {
        $this->createFolder ($this->uploadPath);
        $file->move (storage_path ('app/' . $this->uploadPath), $resource->id . '.' . $file->getClientOriginalExtension ());
    }
156093
public function setFile(File $file = null)
    {
        $this->file = $file;

        if (!empty($file)) {
            $size = @getimagesize($file->getPathname());

            if (is_array($size)) {
                list($this->width, $this->height) = $size;
            }

            $this->refreshUpdatedAt();
        }

        return $this;
    }
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());
    }
1287644
protected function ensureEloquentFile($file)
    {

        if (!$file instanceof EloquentFile) {
            throw new TypeException("File has to be EloquentFile not " . Type::of($file));
        }

        if ($this->urlMapper) {
            $file->setUrlMapper($this->urlMapper);
        }

        return $file;

    }
347775
public function set($file)
    {
        //Resets `$error`
        unset($this->error);

        $this->file = (object)$file;

        //Errors messages
        $errors = [
            UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the maximum size that was specified in php.ini',
            UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the maximum size that was specified in the HTML form',
            UPLOAD_ERR_PARTIAL => 'The uploaded file was partially uploaded',
            UPLOAD_ERR_NO_FILE => 'No file was uploaded',
            UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder',
            UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk',
            UPLOAD_ERR_EXTENSION => 'File upload stopped by extension',
            'default' => 'Unknown upload error',
        ];

        //Checks errors during upload
        if (!isset($file['error']) || $file['error'] !== UPLOAD_ERR_OK) {
            //Gets the default error message, if the error can not be
            //  identified or if the key is not present
            if (!isset($file['error']) || !array_key_exists($file['error'], $errors)) {
                $file['error'] = 'default';
            }

            $this->setError($errors[$file['error']]);
        }

        return $this;
    }
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())
        ;
    }
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,
            ];
        }
    }
1005613
public static function getDataUriFromUploadedFile(UploadedFile $file)
    {
        return sprintf('data:%s;base64,%s', $file->getMimeType(), base64_encode(file_get_contents($file->getPathname())));
    }
309530
public function createUmbrellaFile(UploadedFile $file, $upload = false)
    {
        $umbrellaFile = new UmbrellaFile();
        $umbrellaFile->name = $file->getClientOriginalName();
        $umbrellaFile->md5 = md5_file($file->getRealPath());
        $umbrellaFile->mimeType = $file->getMimeType();
        $umbrellaFile->size = $file->getSize();

        if ($upload) {
            $umbrellaFile->path = $this->upload($file);
        } else {
            $umbrellaFile->file = $file;
        }
        return $umbrellaFile;
    }