定制 mheads/yii-filestorage 二次开发

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

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

mheads/yii-filestorage

Composer 安装命令:

composer require mheads/yii-filestorage

包简介

Core file storage facade for Yii3/yiisoft projects.

README 文档

README

A unified facade for working with uploaded files in Yii3 / yiisoft projects.

The package separates file handling into three responsibilities:

  • Storage - one facade for add(), findById(), remove(), getUrl(), getContent(), and getResource().
  • StoreInterface - physical file storage, for example public or private filesystem storage.
  • RepositoryInterface - file metadata storage.

The core package contains the facade, file entity, repository/store contracts, filesystem stores, and a lightweight demo repository for local examples. DB and ActiveRecord integrations live in separate adapter packages: mheads/yii-filestorage-db and mheads/yii-filestorage-active-record.

Requirements

  • PHP 8.3 - 8.5.
  • yiisoft/files ^2.1.
  • yiisoft/strings ^2.7.
  • psr/http-message ^2.0.

Installation

Install the package with Composer:

composer require mheads/yii-filestorage

Adapters

Install an adapter when file metadata must be stored outside the demo repository:

Quick Start

1. Configure storage

For manual configuration:

use Mheads\Yii\Filestorage\Repository\DemoRepository;
use Mheads\Yii\Filestorage\Storage;
use Mheads\Yii\Filestorage\StorageProvider;
use Mheads\Yii\Filestorage\Store\FileSystem\PublicFileSystemStore;

$repository = new DemoRepository('/app/runtime/demo-filestorage.json');

$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);

For production metadata storage, install mheads/yii-filestorage-db, mheads/yii-filestorage-active-record, or implement a repository adapter.

2. Add and read a file

/** @var \Mheads\Yii\Filestorage\StorageInterface $storage */

$file = $storage->add($uploadedFile, groupName: 'products');

$url = $storage->getUrl($file);
$content = $storage->getContent($file);
$resource = $storage->getResource($file);

$sameFile = $storage->findById($file->getId());
if($sameFile !== null) {
    $storage->remove($sameFile);
}

See Usage basics for details.

Documentation

Examples

examples/* are reference/demo scripts. Adapt them to your project runtime: paths, bootstrap, and launch method.

See examples/README.md.

License

The package is released under the BSD 3-Clause License.

统计信息

  • 总下载量: 24
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 1

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固