定制 mheads/yii-filestorage-db 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-06-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固