big-dream/thinkphp-filesystem-cos
Composer 安装命令:
composer require big-dream/thinkphp-filesystem-cos
包简介
ThinkPHP 8 文件系统驱动 COS 版
关键字:
README 文档
README
适用于 topthink/think-filesystem 的腾讯云对象储存(COS)驱动。
安装
composer require big-dream/thinkphp-filesystem-cos:dev-main
配置
编辑 config/filesystem.php 文件,在该文件里增加一项磁盘配置信息。
<?php return [ // 默认磁盘 'default' => env('filesystem.driver', 'local'), // 磁盘列表 'disks' => [ 'local' => [ 'type' => 'local', 'root' => app()->getRuntimePath() . 'storage', ], 'public' => [ // 磁盘类型 'type' => 'local', // 磁盘路径 'root' => app()->getRootPath() . 'public/storage', // 磁盘路径对应的外部URL路径 'url' => '/storage', // 可见性 'visibility' => 'public', ], /** 以下为新增的磁盘配置信息 **/ 'cos' => [ 'type' => \bigDream\thinkphp\filesystem\Cos::class, // 磁盘路径对应的外部URL路径 'url' => 'https://example-10020201024.cos.ap-guangzhou.myqcloud.com', // 请求协议 'schema' => 'http', // 可见性 'visibility' => '', // 地域 'region' => 'ap-guangzhou', // 应用ID 'app_id' => 10020201024, // 密钥ID 'secret_id' => 'AKIDsiQzQla780mQxLLU2GJCxxxxxxxxxxx', // 密钥KEY 'secret_key' => 'b0GMH2c2NXWKxPhy77xhHgwxxxxxxxxxxx', // 储存桶名称 'bucket' => 'example', // 路径前缀 'prefix' => '', ], /** 以上为新增的磁盘配置信息 **/ // 更多的磁盘配置信息 ], ];
使用
示例控制器代码
app/controller/Index.php:
<?php namespace app\controller; class Index { public function index() { // 如果是GET请求则显示上传表单界面 if (\think\facade\Request::isGet()) { return '<form action="" method="post" enctype="multipart/form-data">' . '<input type="file" name="file">' . '<button type="submit">Upload</button>' . '</form>'; } try { // 获取上传的文件,如果有上传错误,会抛出异常 $file = \think\facade\Request::file('file'); // 如果上传的文件为null,手动抛出一个异常,统一处理异常 if (null === $file) { // 异常代码使用UPLOAD_ERR_NO_FILE常量,方便需要进一步处理异常时使用 throw new \Exception('请上传文件', UPLOAD_ERR_NO_FILE); } // 获取磁盘实例 $disk = \think\facade\Filesystem::disk('cos'); // 保存文件到 avatar 目录 $path = $disk->putFile('avatar', $file); // 获取 URL $url = $disk->url($path); } catch (\Exception $e) { // 如果上传时有异常,会执行这里的代码,可以在这里处理异常 return json([ 'code' => 1, 'msg' => $e->getMessage(), ]); } $info = [ // 文件路径:avatar/a4/e7b9e4ce42e2097b0df2feb8832d28.jpg 'path' => $path, // URL路径:https://example-10020201024.cos.ap-guangzhou.myqcloud.com/storage/avatar/a4/e7b9e4ce42e2097b0df2feb8832d28.jpg 'url' => $url, // 文件大小(字节) 'size' => $file->getSize(), // 文件名:读书顶个鸟用.jpg 'name' => $file->getOriginalName(), // 文件MINE:image/jpeg 'mime' => $file->getMime(), ]; halt($info); } }
依赖
big-dream/thinkphp-filesystem-cos 适用场景与选型建议
big-dream/thinkphp-filesystem-cos 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 118 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 12 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「filesystem」 「driver」 「thinkphp」 「cos」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 big-dream/thinkphp-filesystem-cos 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 big-dream/thinkphp-filesystem-cos 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 big-dream/thinkphp-filesystem-cos 相关的其它包
同方向 / 同关键字的高下载量 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
The flysystem adapter for yandex disk rest api.
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
Galera cluster driver for Doctrine
A PHP client driver for the RethinkDB query language (ReQL)
统计信息
- 总下载量: 118
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-12-13