PHPackages                             qingbing/pf-tools-upload - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. qingbing/pf-tools-upload

ActiveLibrary[File &amp; Storage](/categories/file-storage)

qingbing/pf-tools-upload
========================

工具——文件上传部件，验证

1.0.1(7y ago)0643MITPHP

Since Mar 20Pushed 7y agoCompare

[ Source](https://github.com/qingbing/pf-tools-upload)[ Packagist](https://packagist.org/packages/qingbing/pf-tools-upload)[ Docs](http://www.phpcorner.net)[ RSS](/packages/qingbing-pf-tools-upload/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (2)Used By (3)

pf-tools-upload
===============

[](#pf-tools-upload)

描述
--

[](#描述)

工具——文件上传部件，验证

注意事项
----

[](#注意事项)

- 支持普通文件域上传，模型文件域上传，验证模型文件域上传
- 上传都是通过\\UploadFile::getInstance...(); 来手动上传
- 支持文件上传验证：主要验证是否必传，文件后缀，文件大小，文件的mime-type等
- 文件url和path管理可使用或参考"UploadManager"：使用getUrl 和 getPath
- 文件上传验证类型（标识）：\\UploadFile::VALID\_CLASS

使用方法
----

[](#使用方法)

### 1. 普通文件域上传

[](#1-普通文件域上传)

```
            // 获取上传实例
            $upload = UploadFile::getInstanceByName('upload');
            if (null === $upload) {
                throw new Exception('请选择要上传的文件');
            }
            $filename = time() . '.' . $upload->getExtensionName();
            // 上传文件
            if (!$upload->saveAs(UploadManager::getPath('avatars', true) . DS . $filename)) {
                throw new Exception('上传图像错误，请联系管理员');
            }
            $this->success('文件上传成功', -1);
```

### 2. 模型文件域上传

[](#2-模型文件域上传)

```
            // 获取上传实例
            $upload = UploadFile::getInstance($model, 'upload');
            if (null === $upload) {
                throw new Exception('请选择要上传的文件');
            }
            $filename = time() . '.' . $upload->getExtensionName();
            // 上传文件
            if (!$upload->saveAs(UploadManager::getPath('model', true) . DS . $filename)) {
                throw new Exception('上传图像错误，请联系管理员');
            }
            $this->success('文件上传成功', -1);
```

### 3. 验证模型文件域上传

[](#3-验证模型文件域上传)

#### 3.1 验证model

[](#31-验证model)

```
class TestUploadValid extends FormModel
{
    public $version;
    public $upload;

    public function rules()
    {
        return [
            ['version', 'string', 'allowEmpty' => false],
            ['upload', \UploadFile::VALID_CLASS, 'allowEmpty' => false, 'types' => ['gif', 'png', 'jpg', 'jpeg'],],
        ];
    }

    /**
     * 上传文件并处理
     * @return bool
     * @throws \Exception
     */
    public function save()
    {
        if (!$this->validate()) {
            return false;
        }
        // 获取上传实例
        $upload = \UploadFile::getInstance($this, 'upload');
        if (null === $upload) {
            $this->addError('upload', '请选择要上传的文件');
            return false;
        }
        $filename = time() . '.' . $upload->getExtensionName();
        // 上传文件
        if (!$upload->saveAs(UploadManager::getPath('valid', true) . DS . $filename)) {
            $this->addError('upload', '上传图像错误');
        }
        return true;
    }
}
```

#### 3.2 控制器

[](#32-控制器)

```
            $model->setAttributes($_POST['TestUploadValid']);
            if ($model->save()) {
                $this->success('', -1);
            } else {
                $this->failure('操作失败', $model->getErrors());
            }
```

### 4. getUrl 和 getPath 使用

[](#4-geturl-和-getpath-使用)

```
        // 获取上传文件目录，无则创建
        var_dump(UploadManager::getPath('valid', true));

        // 获取上传文件的访问URL
        var_dump(UploadManager::getUrl('avatars') . '1546831660.txt');
        var_dump(UploadManager::getUrl('avatars', true) . '1546831660.txt');
```

====== 异常代码集合 ======
--------------------

[](#-异常代码集合-)

异常代码格式：1022 - XXX - XX （组件编号 - 文件编号 - 代码内异常）

```
 - 102200101 : "{file}"上传不完整
 - 102200102 : "{file}"的临时上传文件丢失
 - 102200103 : 持久化"{file}"失败
 - 102200104 : 没有支持文件上传的扩展
 - 102200105 : "\UploadSupports\FileValidator.types"必须为数组
 - 102200106 : "\UploadSupports\FileValidator.mimeTypes"必须为数组

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2609d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9379d2ee4885074de75faa3fa12970614186826f762df3c4aa0905dc1ff3b513?d=identicon)[qingbing](/maintainers/qingbing)

---

Top Contributors

[![qingbing](https://avatars.githubusercontent.com/u/33932784?v=4)](https://github.com/qingbing "qingbing (2 commits)")

---

Tags

phpvalidatormodelvalidateupload

### Embed Badge

![Health badge](/badges/qingbing-pf-tools-upload/health.svg)

```
[![Health](https://phpackages.com/badges/qingbing-pf-tools-upload/health.svg)](https://phpackages.com/packages/qingbing-pf-tools-upload)
```

###  Alternatives

[sopamo/laravel-filepond

Laravel backend module for filepond uploads

215272.2k3](/packages/sopamo-laravel-filepond)[eddturtle/direct-upload

Composer Package to build an AWS Signature ready to Direct Upload to S3

88728.1k2](/packages/eddturtle-direct-upload)[blueimp/jquery-file-upload

File Upload widget for jQuery.

141.5M18](/packages/blueimp-jquery-file-upload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
