mheads/yii-filestorage-db
Composer 安装命令:
composer require mheads/yii-filestorage-db
包简介
README 文档
README
Database metadata repository adapter for mheads/yii-filestorage.
The package provides DbRepository, a RepositoryInterface implementation that stores file metadata in a database through yiisoft/db.
Physical file storage remains the responsibility of the core package stores, for example PublicFileSystemStore and PrivateFileSystemStore.
Use it when you want the core Storage facade with persistent database-backed file metadata.
Installation
composer require mheads/yii-filestorage-db
Also install the database driver used by your project:
composer require yiisoft/db-mysql
Apply the migration for mh_filestorage_file before adding files:
For full requirements and supported drivers, see Prerequisites and installation.
Quick Start
use Mheads\Yii\Filestorage\Db\DbRepository; use Mheads\Yii\Filestorage\Storage; use Mheads\Yii\Filestorage\StorageProvider; use Mheads\Yii\Filestorage\Store\FileSystem\PublicFileSystemStore; $repository = new DbRepository($db); $storage = new Storage( repository: $repository, stores: [ new PublicFileSystemStore( name: 'upload', path: '/app/runtime/upload', baseUrl: 'https://cdn.example.com/upload', ), ], defaultStoreName: 'upload', defaultGroupName: 'common', ); StorageProvider::set($storage);
$file = $storage->add($uploadedFile, groupName: 'products'); $url = $file->getUrl(); $sameFile = $storage->findById($file->getId()); if($sameFile !== null) { $storage->remove($sameFile); }
StorageProvider::set() is required only when file objects call getUrl(), getContent(), or getResource() directly.
If you do not register the provider, call these methods through Storage instead.
Documentation
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2026-06-04