yzh52521/filesystem
Composer 安装命令:
composer require yzh52521/filesystem
包简介
Flysystem V2 adapter for the webman
README 文档
README
composer require yzh52521/filesystem
配置文件在 config/plugin/yzh52521/filesystem 下
return [
'default' => 'local',
'storage' => [
'local' => [
'driver' => \yzh52521\Filesystem\Adapter\LocalAdapter::class,
'root' => public_path(),
],
'memory' => [
'driver' => \yzh52521\Filesystem\Adapter\MemoryAdapter::class,
],
's3' => [
'driver' => \yzh52521\Filesystem\Adapter\S3Adapter::class,
'key' => 'S3_KEY',
'secret' => 'S3_SECRET',
'region' => 'S3_REGION',
'version' => 'latest',
'bucket_endpoint' => false,
'use_path_style_endpoint' => false,
'endpoint' => 'S3_ENDPOINT',
'bucket_name' => 'S3_BUCKET',
],
'oss' => [
'driver' => \yzh52521\Filesystem\Adapter\AliyunAdapter::class,
'access_id' => 'OSS_ACCESS_ID',
'access_secret' => 'OSS_ACCESS_SECRET',
'bucket' => 'OSS_BUCKET',
'endpoint' => 'OSS_ENDPOINT',
'prefix' => '',
'isCName' => false,
'options' => []
],
'qiniu' => [
'driver' => \yzh52521\Filesystem\Adapter\QiniuAdapter::class,
'access_key' => 'QINIU_ACCESS_KEY',
'secret_key' => 'QINIU_SECRET_KEY',
'bucket' => 'QINIU_BUCKET',
'domain' => 'QINBIU_DOMAIN',
],
'cos' => [
'driver' => \yzh52521\Filesystem\Adapter\CosAdapter::class,
'region' => 'COS_REGION',
'app_id' => 'COS_APPID',
'secret_id' => 'COS_SECRET_ID',
'secret_key' => 'COS_SECRET_KEY',
// 可选,如果 bucket 为私有访问请打开此项
// 'signed_url' => false,
'bucket' => 'COS_BUCKET',
'prefix' => '',
'read_from_cdn' => false,
// 'timeout' => 60,
// 'connect_timeout' => 60,
// 'cdn' => '',
// 'scheme' => 'https',
],
'obs' => [
'driver' => \yzh52521\Filesystem\Adapter\ObsAdapter::class,
'key' => 'OBS_ACCESS_ID',
// <Your Huawei OBS AccessKeyId>
'secret' => 'OBS_ACCESS_KEY',
// <Your Huawei OBS AccessKeySecret>
'bucket' => 'OBS_BUCKET',
// <OBS bucket name>
'endpoint' => 'OBS_ENDPOINT',
// <the endpoint of OBS, E.g: (https:// or http://).obs.cn-east-2.myhuaweicloud.com | custom domain, E.g:img.abc.com> OBS 外网节点或自定义外部域名
'cdn_domain' => 'OBS_CDN_DOMAIN',
//<CDN domain, cdn域名> 如果isCName为true, getUrl会判断cdnDomain是否设定来决定返回的url,如果cdnDomain未设置,则使用endpoint来生成url,否则使用cdn
'ssl_verify' => 'OBS_SSL_VERIFY',
// <true|false> true to use 'https://' and false to use 'http://'. default is false,
'debug' => 'APP_DEBUG',
'prefix' => '',
'bucket_endpoint' => '',
'temporary_url' => '',
// <true|false>
],
],
];
- 阿里云 OSS 适配器
composer require "yzh52521/flysystem-oss:^3.0"
- S3 适配器
composer require "league/flysystem-aws-s3-v3:^3.0"
- 七牛云适配器
composer require "overtrue/flysystem-qiniu:^3.0"
- 内存适配器
composer require "league/flysystem-memory:^3.0"
- 腾讯云 COS 适配器
composer require "overtrue/flysystem-cos:^5.0"
- 华为云 OBS 适配器
composer require "yzh52521/flysystem-obs:^2.0"
使用
通过Filesystem::disk('local') 来调用不同的适配器
使用
use yzh52521\Filesystem\Facade\Filesystem;
public function upload(\support\Request $request){
$file = $request->file('file');
$result = Filesystem::putFile('webman',$file);
//文件判断
try {
validate(
[
'image' => [
// 限制文件大小(单位b),这里限制为4M
'fileSize' => 4 * 1024 * 1000,
// 限制文件后缀,多个后缀以英文逗号分割
'fileExt' => 'gif,jpg,png,jpeg'
]
]
)->check(['image' => $file]);
$path = Filesystem::disk('local')->putFile('webman',$file);
}catch (\yzh52521\validate\exception\ValidateException | \Exception $e){
print($e->getMessage());
}
//获取上传文件
$fileUrl = Filesystem::url($path);
//指定选定器外网
$fileUrl = Filesystem::disk('oss')->url($path);
}
用例中使用了 validate 验证器
安装 validate
composer require "yzh52521/webman-validate"
###静态方法(可单独设定)
| 方法 | 描述 | 默认 |
|---|---|---|
| disk | 选定器 | config中配置的default |
| url | 获取文件访问地址 | |
| putFile | 保存文件 | |
| putFileAs | 指定文件名保存文件 | |
| put | 保存文件 |
yzh52521/filesystem 适用场景与选型建议
yzh52521/filesystem 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 231 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 02 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「filesystem」 「s3」 「ftp」 「oss」 「qiniu」 「cos」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yzh52521/filesystem 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yzh52521/filesystem 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yzh52521/filesystem 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
A PHP class providing static methods for reading, writing, copying, moving, and deleting files and directories, MIME type detection, image size detection, and file permission management
A PHP SNMP library for people who hate SNMP, MIBs and OIDs!
The flysystem adapter for yandex disk rest api.
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
This is a Flysystem adapter for the Aliyun OSS.
统计信息
- 总下载量: 231
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-25