PHPackages                             sunsgne/webman-multipart-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sunsgne/webman-multipart-upload

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sunsgne/webman-multipart-upload
===============================

multipart upload

0.2.0(2y ago)18MITPHPPHP &gt;=8.1

Since Jul 21Pushed 2y ago1 watchersCompare

[ Source](https://github.com/sunsgneayo/webman-multipart-upload)[ Packagist](https://packagist.org/packages/sunsgne/webman-multipart-upload)[ RSS](/packages/sunsgne-webman-multipart-upload/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

 [![sunsgne](https://camo.githubusercontent.com/e366b0a276ef18e50c689cb143c8f78eadfa2e14e8af4a8e9e1628362ad93f1e/68747470733a2f2f63646e2e6e696e65313132302e636e2f6c6f676f2d692e706e67)](https://camo.githubusercontent.com/e366b0a276ef18e50c689cb143c8f78eadfa2e14e8af4a8e9e1628362ad93f1e/68747470733a2f2f63646e2e6e696e65313132302e636e2f6c6f676f2d692e706e67)

sunsgne/webman-multipart-upload

🐬 Webman's File multipart upload 🐬

[![Latest Stable Version](https://camo.githubusercontent.com/dfa1665427e5d2f32df9eaee8fcf1ede6646c44c44f0f4282ee5ec37b929bb71/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f7765626d616e2d6d756c7469706172742d75706c6f61642f76)](https://packagist.org/packages/sunsgne/webman-multipart-upload)[![Total Downloads](https://camo.githubusercontent.com/a3cc93e12823cf7fe6def26ac03be93fc7da40c90d931067bc8cfc0c154f7bdd/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f7765626d616e2d6d756c7469706172742d75706c6f61642f646f776e6c6f616473)](https://packagist.org/packages/sunsgne/webman-multipart-upload)[![Latest Unstable Version](https://camo.githubusercontent.com/dbdc469bc76aa6ad8c725723154562780ae5a194e51ea27eac34f056f5986e28/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f7765626d616e2d6d756c7469706172742d75706c6f61642f762f756e737461626c65)](https://packagist.org/packages/sunsgne/webman-multipart-upload)[![License](https://camo.githubusercontent.com/ee43f732bea8e5270059d04608e8469dd41d72eb8bb8b54b252cd0b77b04f2be/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f7765626d616e2d6d756c7469706172742d75706c6f61642f6c6963656e7365)](https://packagist.org/packages/sunsgne/webman-multipart-upload)[![PHP Version Require](https://camo.githubusercontent.com/e0b69ecd8f45d54cd285f6c0be7c7f73401cf78739b3dadb38f4c6d1ef2f35f7/687474703a2f2f706f7365722e707567782e6f72672f73756e73676e652f7765626d616e2d6d756c7469706172742d75706c6f61642f726571756972652f706870)](https://packagist.org/packages/sunsgne/webman-multipart-upload)

### 说明

[](#说明)

这是一个基于 PHP 实现的大文件分片上传开源项目，它允许用户将大文件分成小片段进行上传，并最终合并为完整的文件。项目利用文件的 MD5 值进行分片上传和合并请求，确保数据的完整性和准确性。

### 如何工作？

[](#如何工作)

通常情况下，上传大文件可能会面临以下问题：上传过程中的网络不稳定、上传耗时过长、服务器内存不足等。为了解决这些问题，本示例项目采用了分片上传的策略，将大文件拆分成若干小片段，分别上传到服务器。一旦所有分片都上传完成，服务器再将这些分片按照特定算法合并为完整的文件。

整个过程主要分为以下几个步骤：

- 文件拆分：客户端将待上传的大文件拆分成固定大小的小片段，通常称为分片或块。
- 分片上传：客户端逐个将这些分片上传到服务器，每个分片都带有它在整个文件中的偏移量信息和对应的 MD5 值。
- 服务器存储：服务器接收到上传的分片后，将其存储在一个临时目录中，等待所有分片都上传完毕。
- 分片合并：当所有分片都上传完毕后，服务器根据接收到的分片顺序和 MD5 值进行验证，确保所有分片的完整性。然后按顺序将它们合并为完整的文件。
- 清理临时文件：合并完成后，服务器将删除所有临时存储的分片文件，释放空间。

### 引用

[](#引用)

```
composer require sunsgne/webman-multipart-upload
```

### 在webman中使用

[](#在webman中使用)

伪代码 仅供参考：

```
    public function MultipartUpload(Request $request): Response
    {
        try {
            $data = v::input($request->post(), [
                'action'      => v::nullable(v::stringVal()->in(['slice', 'merge']))->setName("action"),
                'filename'    => v::stringVal()->setName("filename"),
                'chunk'       => v::nullable(v::intVal()->min(0))->setName("chunk"),
                'chunkLength' => v::intVal()->min(0)->setName("chunkLength"),
                'uuid'        => v::stringVal()->setName("uuid"),
            ]);
            $apk  = $request->file('files');
            /** 验证上传分片必须的参数 */
            if ($request->post('action') == 'slice' && is_null($request->post('chunk'))) {
                return response_error(ErrorCode::BAD_REQUEST, "chunk required, parameter[action ,chunk] should appear at the same time");
            }
            if ($request->post('action') == 'slice' && empty($request->file('files'))) {
                return response_error(ErrorCode::BAD_REQUEST, "upload error,parameter[slice ,file] should appear at the same time");
            }

            $sdk = new MultipartUpload();
            if ($data['action'] == 'slice') {
                /** 保存分片 */
                return response_success(
                    $sdk->upload($data['uuid'], $apk, intval($data['chunk']))
                );
            }
            /** @var  $mergeInfo *合并分片 */
            $mergeInfo = $sdk->merge($data['uuid'], intval($data['chunkLength']), $data['filename']);
            return response_success($mergeInfo);
        } catch (UploadException $e) {
            return response_error(ErrorCode::BAD_REQUEST, $e->getMessage());
        }
    }
```

### 前端示例

[](#前端示例)

详见： `./example/upload.html`

### 注意事项

[](#注意事项)

- 为了保证文件的完整性，建议在客户端和服务器端同时校验 MD5 值。
- 分片大小需要根据网络环境和服务器配置进行调整，以达到最佳上传性能。
- 请确保服务器具有足够的磁盘空间来存储大文件的分片和最终合并后的完整文件。

### 贡献

[](#贡献)

欢迎对该项目提供贡献！您可以提交问题、建议或者发起 Pull Request。在贡献前，请确保您的代码符合项目的编码规范。

### 授权

[](#授权)

本项目基于开源协议 MIT License 发布，您可以自由使用、修改和分发本项目，但请在您的项目中包含原始项目的授权信息。

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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

1026d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/65843af70bae47cda80e0386c0640e2e17e1f8c8a12ea8fade3e1297237b26f3?d=identicon)[sunsgneayo](/maintainers/sunsgneayo)

---

Top Contributors

[![sunsgneayo](https://avatars.githubusercontent.com/u/51745500?v=4)](https://github.com/sunsgneayo "sunsgneayo (13 commits)")

### Embed Badge

![Health badge](/badges/sunsgne-webman-multipart-upload/health.svg)

```
[![Health](https://phpackages.com/badges/sunsgne-webman-multipart-upload/health.svg)](https://phpackages.com/packages/sunsgne-webman-multipart-upload)
```

###  Alternatives

[components/modernizr

Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user's browser.

10254.3k8](/packages/components-modernizr)

PHPackages © 2026

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