PHPackages                             janfish/storage - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. janfish/storage

ActiveLibrary[File &amp; Storage](/categories/file-storage)

janfish/storage
===============

Client of distributed file storage service

v1.2(6y ago)131MITPHPPHP &gt;=7.0.0

Since Jul 13Pushed 6y agoCompare

[ Source](https://github.com/zeng444/cdn.storage)[ Packagist](https://packagist.org/packages/janfish/storage)[ RSS](/packages/janfish-storage/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (4)Used By (0)

中央储存服务
======

[](#中央储存服务)

背景
--

[](#背景)

- 图片存储作为基础服务，独立于各个应用外，通过远程调用发送图片到存储服务中。存储服务集中管理文件的创建，复制，删除以及CDN服务

客户端程序
-----

[](#客户端程序)

### 注入phalcon

[](#注入phalcon)

```
$di->set('cloudStorage', function () use ($config) {
    return new CloudStorage([
        'version' => 'GridFs',
        'api' => 'http://disk.xy.cn/',
        'imagePrefix' => 'http://cdn.xy.cn/',
        'tag' => 'insurance',
        'appId' => 'test',
        'appSecret' => 'test123456',
    ]);
});
```

- 参数配置说明

参数类型默认值说明versionstringdefault版本，GridFs和default分别使用两种存储方式，不填写默认为defaultapistring服务地址httpappIdstring访问凭证IDappSecretstring访问凭密码imagePrefixstringCDN地址pathTypestringWEEK生成日期文件的类型WEEK DAY MONTHtagstring定义私有根目录，需要服务端开通可以使用的TAGallowedarray允许上传的文件格式，数组默认图片的mime信息，需要小于等于服务端的设置maxSizeint允许上传的文件大小,单位mb，需要小于服务端的设置gzipbooleantrue传输开启gzip压缩DEV测试api参数为

```
api: http://disk.xy.cn/
appId: test
appSecret: test123456

```

### 调用上传

[](#调用上传)

#### 单文件上传

[](#单文件上传)

```
$result = $cloudStorage->setFile($_FILES[0]['tmp_name'])->upload();
if ($result === false) {
    return $app->apiResponse->error($cloudStorage->getError());
}
$images = $cloudStorage->getResult();

```

#### 指定文件后缀

[](#指定文件后缀)

> 服务端会先使用文件后缀，如果文件没有后缀，可以通过setFile的第二参数指定后缀，如果也无，服务器会尝试使用上传文件的MIME信息判断可能的对应文件后缀

```
$result = $cloudStorage->setFile($_FILES[0]['tmp_name'],'.jpg)->upload();
if ($result === false) {
    return $app->apiResponse->error($cloudStorage->getError());
}
$images = $cloudStorage->getResult();

```

返回的数据

```
[
    {
        "status": "200",
        "oid": "5d29f7b04e110f00085fbab2",
        "path": "insurance/201928/2332727541.jpeg",
        "url": "http://cdn.xy.cn/insurance/201928/2332727541.jpeg"
    }
]
```

#### 指定tag上传

[](#指定tag上传)

```
$result = $cloudStorage->setFile($_FILES[0]['tmp_name'])->setTag('test')->upload();
if ($result === false) {
    return $app->apiResponse->error($cloudStorage->getError());
}
$images = $cloudStorage->getResult();

```

#### 批量上传

[](#批量上传)

> 这里无法指定文件后缀，所以设置的上传文件最好本身带有后缀

```
$cloudStorage = $app->cloudStorage;
$files = array_column($_FILES, 'tmp_name');
$cloudStorage->setFiles($files);
$cloudStorage->setTag('insurance');
if ($cloudStorage->upload() === false) {
    echo $cloudStorage->getError();
}
$images = $cloudStorage->getResult();

```

返回的数据

```
[
    {
        "status": "200",
        "oid": "5d29f7b04e110f00085fbab2",
        "path": "insurance/201928/2332727541.jpeg",
        "url": "http://cdn.xy.cn/insurance/201928/2332727541.jpeg"
    },
    {
        "status": "200",
        "oid": "5d29f7b04e110f00085fbab2",
        "path": "insurance/201928/106785628.jpeg",
        "url": "http://cdn.xy.cn/insurance/201928/106785628.jpeg"
    }
]
```

本地约束限制设置（服务端针对appid也有限制，权限应该在服务端的限制之下）

```
$result = $app->cloudStorage->setAllowed([
     'image/jpeg',
     'image/jpg',
     'image/png',
     'application/zip',
     'application/x-rar',
     'application/x-zip-compressed',
 ])
 ->setMaxSize(5)
 ->setFiles(array_column($_FILES, 'tmp_name'))
 ->setTag('insurance')->upload();
if ($result === false) {
   echo $app->cloudStorage->getError()
}

```

### 删除文件

[](#删除文件)

```
$cloudStorage = $app->cloudStorage;
if ($cloudStorage->remove(['insurance/201928/106785628.jpeg','insurance/201928/2332727541.jpeg']) === false) {
    echo  $cloudStorage->getError();
}
```

### 调用地址

[](#调用地址)

#### 获取CDN地址

[](#获取cdn地址)

> 上传接口返回的path一般本地存取，通过拼装函数获得最终CDN地址

```
echo $app->cloudStorage->getStaticUrl('insurance/201928/2332727541.jpeg');
```

输出数据

```
http://cdn.xy.cn/insurance/201928/2332727541.jpeg

```

#### 图片在线裁剪（需要CDN支持）

[](#图片在线裁剪需要cdn支持)

```
echo $app->cloudStorage->getStaticUrl('insurance/201928/2332727541.jpeg',['width'=>100,'height'=>100,clipType='1']);
```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

3

Last Release

2535d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/60a62fd9f299f25558ac4a898ae3833bd7185ba4706bb167a8cabf05a3d96955?d=identicon)[Robert Zeng](/maintainers/Robert%20Zeng)

---

Top Contributors

[![zeng444](https://avatars.githubusercontent.com/u/941266?v=4)](https://github.com/zeng444 "zeng444 (18 commits)")

### Embed Badge

![Health badge](/badges/janfish-storage/health.svg)

```
[![Health](https://phpackages.com/badges/janfish-storage/health.svg)](https://phpackages.com/packages/janfish-storage)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
