Sets the uploaded file to be validated and moved
@param UploadedFile $file
@return mixed
499953
public function file(UploadedFile $file)
	{
		$this->file = $file;
		$this->filename = $file->getClientOriginalName();
		$this->sanitizeFilename();

		return $this;
	}
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;
    }
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;
    }
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;
    }
23633
protected function validate(UploadFile $file)
    {
        if (parent::validate($file)) {

            $info = getimagesize($file->getFileTemp());
            $width = $info[ 0 ];
            $height = $info[ 1 ];

            /* Validate width min size */
            if ($this->allowedImageSize[ 'width' ][ 'min' ] > 0) {
                if ($width < $this->allowedImageSize[ 'width' ][ 'min' ]) {
                    $this->errors[] = language()->getLine(
                        'IMAGE_E_ALLOWED_MIN_WIDTH_SIZE',
                        [$this->allowedFileSize[ 'min' ], $width]
                    );
                }
            }

            /* Validate width max size */
            if ($this->allowedImageSize[ 'width' ][ 'max' ] > 0) {
                if ($width > $this->allowedImageSize[ 'width' ][ 'max' ]) {
                    $this->errors[] = language()->getLine(
                        'IMAGE_E_ALLOWED_MAX_WIDTH_SIZE',
                        [$this->allowedFileSize[ 'max' ], $width]
                    );
                }
            }

            /* Validate height min size */
            if ($this->allowedImageSize[ 'height' ][ 'min' ] > 0) {
                if ($height < $this->allowedImageSize[ 'width' ][ 'min' ]) {
                    $this->errors[] = language()->getLine(
                        'IMAGE_E_ALLOWED_MIN_HEIGHT_SIZE',
                        [$this->allowedFileSize[ 'min' ], $height]
                    );
                }
            }

            /* Validate height max size */
            if ($this->allowedImageSize[ 'height' ][ 'max' ] > 0) {
                if ($height > $this->allowedImageSize[ 'width' ][ 'max' ]) {
                    $this->errors[] = language()->getLine(
                        'IMAGE_E_ALLOWED_MAX_HEIGHT_SIZE',
                        [$this->allowedFileSize[ 'max' ], $height]
                    );
                }
            }
        }

        if (count($this->errors) == 0) {
            return true;
        }

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

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

        return $response;
    }
885256
private function uploadFile(UploadedFile $file)
    {
        /** @var FileStorage $fileStorage */
        $fileStorage = Yii::$app->get('fileStorage');

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

        return $fileStorage->put($filename, $file->name);
    }
1011250
private function getExtension(UploadedFile $file): ?string
    {
        $originalName = $file->getClientOriginalName();

        if ($extension = pathinfo($originalName, PATHINFO_EXTENSION)) {
            return strtolower($extension);
        }

        if ($extension = $file->guessExtension()) {
            return strtolower($extension);
        }

        return null;
    }
729500
protected function uploadAndDeleteOriginal(UploadedFile $file)
    {
        $this->renameIfExists($file);

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

        $this->destroy();

        return $path;
    }
947903
private function upload($file)
    {
        $file = $this->model->createFile($this->attribute, $file->tempName, $file->name);
        if ($file) {
            if ($this->saveAfterUpload) {
                $this->model->save(false);
            }
            $presetAfterUpload = $this->model->filePresetAfterUpload($this->attribute);
            if (count($presetAfterUpload)) {
                $this->applyPreset($presetAfterUpload, $file);
            }
            $template = $this->model->fileOption($this->attribute, 'template');
            if ($template) {
                return $this->response(
                    $this->controller->renderFile(Yii::getAlias($template), [
                        'file' => $file,
                        'model' => $this->model,
                        'attribute' => $this->attribute
                    ])
                );
            }
            return $this->response([
                $this->resultFieldId => $file->getPrimaryKey(),
                $this->resultFieldPath => $this->model->fileUrl($this->attribute, $file),
            ]);
        }
        return $this->response(['error' => Yii::t('filemanager-yii2', 'Error saving file')]); // @codeCoverageIgnore
    }
332126
public function up(UploadedFile $file)
    {
        //设置文件名称
        $this->oriName = $file->name;
        //设置文件大小
        $this->fileSize = $file->size;
        $this->fileType = $this->getExtension();
        $this->fullName = $this->getFullName();
        $this->filePath = $this->getFilePath();
        $this->fileName = $this->getFileName();
        $dirName = dirname($this->filePath);
        if (!is_dir($dirName)) {//递归创建保存目录
            FileHelper::createDirectory($dirName, $this->dirMode, true);
        }
        if (!($file->saveAs($this->filePath) && file_exists($this->filePath))) {
            $this->stateInfo = Yii::t('attachment', 'An error occurred while saving the file.');
            return false;
        } else { //移动成功
            $this->saveModel();
            $this->stateInfo = 'SUCCESS';
            return true;
        }
    }
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;
    }
960495
private function isUploaded($file): bool
    {
        if (is_string($file)) {
            //We can use native method
            return is_uploaded_file($file);
        }

        if (is_array($file)) {
            return isset($file['tmp_name']) && (
                    is_uploaded_file($file['tmp_name']) || isset($file['uploaded'])
                );
        }

        if ($file instanceof UploadedFileInterface) {
            return empty($file->getError());
        }

        //Not uploaded
        return false;
    }
766343
public function uploadFile(UploadedFile $file)
    {
        $path =   $this->env . '/'  . md5(time() . random_int(1,100000)) . '.'. $file->guessClientExtension();
        /** @var Result $result */
        $result = $this->client->putObject([
            'ACL' => 'public-read',
            'Bucket' => $this->bucketName,
            'SourceFile' => $file->getRealPath(),
            'Key' => $path
        ]);

        return new FileUploadedModel($path, $result->get('ObjectURL'), FileUploadedModel::VENDOR_S3);
    }
490661
public static function create(array $file)
    {
        if (!isset($file[ 'tmp_name' ])) {
            throw new \InvalidArgumentException('The tmp_name key is required.');
        }

        return new UploadedFile(
            $file[ 'tmp_name' ],
            isset($file[ 'name' ])
            ? $file[ 'name' ]
            : null,
            isset($file[ 'size' ])
            ? $file[ 'size' ]
            : null,
            isset($file[ 'type' ])
            ? $file[ 'type' ]
            : null,
            isset($file[ 'error' ])
            ? $file[ 'error' ]
            : UPLOAD_ERR_OK
        );
    }
1023645
private function validateUploadedFiles(array $uploadedFiles)
    {
        foreach ($uploadedFiles as $file) {
            if (is_array($file)) {
                $this->validateUploadedFiles($file);
            } elseif (!$file instanceof UploadedFileInterface) {
                throw new InvalidArgumentException('Invalid entry in uploaded files structure');
            }
        }
    }
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;
        }
    }