slince/upload
Composer 安装命令:
composer require slince/upload
包简介
Process file uploads with multiple and extensible validation rules
README 文档
README
Process uploaded files with multiple and extensible validation rules.
Installation
Install via composer
$ composer require slince/upload
Quick view
$builder = new Slince\Upload\UploadHandlerBuilder(); //create a builder. $handler = $builder ->saveTo(__DIR__ . '/dst') ->getHandler(); $files = $handler->handle(); print_r($files);
Usage
Assume files are uploaded with this HTML form:
<form method="POST" enctype="multipart/form-data"> <input type="file" name="foo" value=""/> <input type="file" name="bar[baz][]" value=""/> <input type="file" name="bar[baz][]" value=""/> <input type="submit" value="Upload File"/> </form>
Server:
$builder = new Slince\Upload\UploadHandlerBuilder(); //create a builder. $handler = $builder ->overwrite(true) // open overwrite mode. //Custom namer ->naming(function (UploadedFile $file) { return date('Y/md') . '/' . uniqid() . '.' . $file->getClientOriginalExtension(); }) //add constraints ->sizeBetween('10m', '20m') ->allowExtensions(['jpg', 'txt']) ->allowMimeTypes(['image/*', 'text/plain']) ->saveTo(__DIR__ . '/dst') //save to local ->getHandler(); $files = $handler->handle(); foreach ($files as $file) { $uploadedFile = $file->getUploadedFile(); if ($file->isUploaded()) { echo $uploadedFile->getClientOriginalName() . ' upload ok, path:' . $file->getMetadata('spl_file')->getPathname(); } else { echo $uploadedFile->getClientOriginalName() . ' upload error: ' . $file->getException()->getMessage(); } echo PHP_EOL; }
File metadata $file->getMetadata('metadata name') is provided by storage layer.
if you are using Local, the file has a metadata named 'spl_file', it is an instance of SplFileInfo.
If you want access attributes of the file saved in the client, you can use like this.
$files['foo']->getUploadedFile()->getClientOriginalName(); // original name $files['bar']['baz'][0]->getUploadedFile()->getClientOriginalExtension(); // original extension $files['bar']['baz'][1]->getUploadedFile()->getClientMimeType(); // original mime type
Integration with flysystem
function createS3Flysystem() { $client = new Aws\S3\S3Client([ 'credentials' => [ 'key' => 'your-key', 'secret' => 'your-secret' ], 'region' => 'your-region', 'version' => 'latest|version', ]); $adapter = new League\Flysystem\AwsS3v3\AwsS3Adapter($client, 'your-bucket-name'); $flysystem = new League\Flysystem\Filesystem($adapter); return $flysystem; } $builder = new Slince\Upload\UploadHandlerBuilder(); //create a builder. $handler = $builder->setFilesystem(new Slince\Upload\Filesystem\Flysystem(createS3Flysystem())) ->getHandler(); $files = $handler->handle(); print_r($files);
All files will be automatically uploaded to AWS S3.
License
The MIT license. See MIT
slince/upload 适用场景与选型建议
slince/upload 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.49k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2014 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「file」 「upload」 「validation」 「file upload」 「http-foundation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 slince/upload 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 slince/upload 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 slince/upload 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Adds request-parameter validation to the SLIM 3.x PHP framework
Laravel Media Popup to upload/view the files
A jQuery augmented PHP library for creating and validating HTML forms
PMVC Plugin for File information
Mapper for accessing resources in KWCMS
统计信息
- 总下载量: 10.49k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 30
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-10-26