PHPackages                             xzhonour/laravel-aliyuncs-oss-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. xzhonour/laravel-aliyuncs-oss-storage

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

xzhonour/laravel-aliyuncs-oss-storage
=====================================

Aliyuncs OSS storage in laravel.

v3.0.1(3y ago)038MITPHP

Since Oct 19Pushed 3y agoCompare

[ Source](https://github.com/xzhonour/laravel-aliyuncs-oss-storage)[ Packagist](https://packagist.org/packages/xzhonour/laravel-aliyuncs-oss-storage)[ RSS](/packages/xzhonour-laravel-aliyuncs-oss-storage/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (3)Used By (0)

Laravel Aliyun OSS Filesystem Storage
=====================================

[](#laravel-aliyun-oss-filesystem-storage)

说明
--

[](#说明)

> 本项目Fork原项目地址 在原项目上以支持 laravel 9.x 不支持 laravel 9 以下版本，对9以下版本支持请访问原项目地址

Install
-------

[](#install)

> composer require xzhonour/laravel-aliyuncs-oss-storage

Require
-------

[](#require)

- Laravel 9.x

Configure
---------

[](#configure)

在 `config/filesystems.php` 的 `disk`里增加配置:

```
 'oss' => [ // 定义的disk名称, 自定义，只要不重复就行
    'driver'            => 'aliyuncs-oss', // 使用的驱动，这里只能填写 `aliyuncs-oss` [必填]
    'access_key_id'     => env('OSS_ACCESS_ID', 'access_key_id'), // OSS access_key_id [必填]
    'access_key_secret' => env('OSS_ACCESS_KEY', 'access_key_secret'), // OSS access_key_secret [必填]
    'endpoint'          => env('OSS_ENDPOINT', 'endpoint'), // OSS endpoint [必填]
    'bucket'            => env('OSS_BUCKET', 'bucket'), // OSS bucket [必填]
    'custom_domain'     => 'http://foo.bar', // 自定义域名， 参考下方说明
    'schema'            => env('OSS_SCHEMA', 'https'), // 使用默认域名时用的 url schema, 参考下方说明
    'plugins'           => [], // 可以自己封装插件，实现更多方法 参考下方说明
 ],

  说明:
  1. 自定义域名
  获取 OSS URL 的时候，默认地址是 bucket.endpoint/path，指定 schema 后为 http(s)://bucket.endpoint/path
  当使用自定义域名后, 就不再使用默认地址，schema 此时就不起作用了, 获取地址变为：自定义域名/path

  2. 插件
  如果要实现更多方法，在 `plugins` 里添加上对应类， 例如
  'plugins' => [
      DoSomethingPlugin::class,
  ],
  插件类应该继承 `XzHonour\AliOSS\Plugins\AbstractPlugin`
  或者继承 `XzHonour\AliOSS\League\Flysystem\Plugin\AbstractPlugin`

```

Use
---

[](#use)

可以使用 Laravel Storage 的所有方法

集成插件提供的方法 :

- signUrl ```
    使用签名URL进行临时授权(主要对私有对象使用).

    Storage::disk('oss')->signUrl($path, $timeout);

    ```
- putRemoteFile ```
    将本地文件或者远程URL文件存储到oss.

    Storage::disk('oss')->putRemoteFile($path, $remoteUrl);

    ```

Notice
------

[](#notice)

1. `deleteDir` 删除文件夹方法. 方法直接返回为 false, 不会进行删除，如果要删除文件夹强烈推荐到阿里云后台操作.
2. `listContents` 列出文件夹目录(支持递归)方法. 方法直接返回为空数组 \[\], 如果有此业务，可以考虑通过插件实现.
3. 除了 `has` 方法, 所有方法在失败的时候都会返回 false (不抛出异常，但有日志记录),

    如果需要, 你可以用 === false 来判断是否成功. 配置正常的情况下, 失败概率极低.
4. `has` 方法, 本身返回 true / false, 所以发生错误会抛出异常.
5. `$request->file('avatar')->store('avatars');` 上传文件直接 `store` 就生成随机名称，这里的 `avatars` 只是目录名称

    所以推荐使用 `storeAs` 方法来达到预期的目的.

    曾经遇到过 `store` 方法生成随机名称获取扩展的时候，对于 WPS 的 docx/pptx, 总是获取不到正确的文件扩展名称

    最后 `storeAs` 手动解决了.
6. `temporaryUrl` 方法和 `signUrl` 是一样的效果, 区别仅在于第二个参数

    `signUrl` 传入的 int 类型, 例如, 传入30表示30秒后过期

    `temporaryUrl` 传入的是 `\DateTimeInterface` 类型, 例如, 传入 now()-&gt;addSeconds(30) 也是表示30秒后过期

support methods
---------------

[](#support-methods)

### 普通写入

[](#普通写入)

> Storage::disk('aliOss')-&gt;write('test.txt','test');

### 写入流

[](#写入流)

> Storage::disk('aliOss') -&gt;writeStream('test1.txt',fopen('./app/Console/Commands/Test/TestCode.php','r'));

### 重命名文件

[](#重命名文件)

> Storage::disk('aliOss')-&gt;rename('test.txt','test3.txt');

### 复制文件到目标

[](#复制文件到目标)

> Storage::disk('aliOss')-&gt;copy('test.txt','temp/test.txt');

### 删除文件夹

[](#删除文件夹)

### 创建文件夹

[](#创建文件夹)

> Storage::disk('aliOss')-&gt;createDirectory('temp1');

### 设置文件访问权限

[](#设置文件访问权限)

> Storage::disk('aliOss')-&gt;setVisibility('test3.txt',Visibility::PUBLIC);

### 文件是否存在

[](#文件是否存在)

> dd(Storage::disk('aliOss')-&gt;fileExists('test3.txt'));

### 读取文件

[](#读取文件)

### 读取文件，流方式

[](#读取文件流方式)

> dd(Storage::disk('aliOss')-&gt;readStream('test1.txt'));

### 列举文件列表

[](#列举文件列表)

```
foreach (Storage::disk('aliOss')->listContents('temp', false) as $content){
             dd($content);
        }
```

### 获取文件元信息

[](#获取文件元信息)

> dd(Storage::disk('aliOss')-&gt;getMetaData('test3.txt'));

### 获取文件大小信息,获取不到时为 -1

[](#获取文件大小信息获取不到时为--1)

> dd(Storage::disk('aliOss')-&gt;getSize('test3.txt'));

### 获取文件mimetype

[](#获取文件mimetype)

> dd(Storage::disk('aliOss')-&gt;mimetype('test3.txt'));

### 获取文件lastModified

[](#获取文件lastmodified)

> dd(Storage::disk('aliOss')-&gt;lastModified('test3.txt'));

### 获取文件访问权限

[](#获取文件访问权限)

> dd(Storage::disk('aliOss')-&gt;visibility('test3.txt'));\\

### 移动文件

[](#移动文件)

> Storage::disk('aliOss')-&gt;move('test3.txt','temp1/test3.txt');

### 文件大小

[](#文件大小)

> dd(Storage::disk('aliOss')-&gt;fileSize('temp1/test3.txt'));

More
----

[](#more)

Storage方法通常会提供 `options` 参数. 最常用的就是设置文件可见性.

设置可见性：

```
// 只设置可见行，直接 public
Storage::disk('oss')->put('file.jpg', $contents, 'public');
或
// 还有其他 option 配置时使用 ['visibility' => 'private']
Storage::disk('oss')->put('file.jpg', $contents, ['visibility' => 'private'])

public 对应 OSS 的公开读权限
private 对应 OSS 的私有权限
不单独设置可见性, 默认继承 bucket 的可见性

```

Links
-----

[](#links)

[https://help.aliyun.com/document\_detail/32099.html](https://help.aliyun.com/document_detail/32099.html)

License
-------

[](#license)

```
        DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                    Version 2, December 2004

 Copyright (C) 2004 Sam Hocevar

 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as long
 as the name is changed.

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. You just DO WHAT THE FUCK YOU WANT TO.

```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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 ~0 days

Total

2

Last Release

1352d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7d27e26c2c2c469b4d3bc879d15235b0c696153ab4fa8329ce7c3a523df88858?d=identicon)[xzhonour](/maintainers/xzhonour)

---

Top Contributors

[![mitoop](https://avatars.githubusercontent.com/u/7368344?v=4)](https://github.com/mitoop "mitoop (6 commits)")

### Embed Badge

![Health badge](/badges/xzhonour-laravel-aliyuncs-oss-storage/health.svg)

```
[![Health](https://phpackages.com/badges/xzhonour-laravel-aliyuncs-oss-storage/health.svg)](https://phpackages.com/packages/xzhonour-laravel-aliyuncs-oss-storage)
```

###  Alternatives

[jacobcyl/ali-oss-storage

aliyun oss filesystem storage for laravel 5+

537573.2k7](/packages/jacobcyl-ali-oss-storage)[iidestiny/flysystem-oss

Flysystem adapter for the Oss storage.

96640.6k29](/packages/iidestiny-flysystem-oss)[xxtime/flysystem-aliyun-oss

AliYun OSS adapter for flysystem. Support PHP8. aliyuncs/oss-sdk-php ~2.6

54523.9k30](/packages/xxtime-flysystem-aliyun-oss)[apollopy/flysystem-aliyun-oss

This is a Flysystem adapter for the Aliyun OSS ~2.3

94128.2k3](/packages/apollopy-flysystem-aliyun-oss)[yangyifan/upload

上传 SDK for Laravel

12422.7k3](/packages/yangyifan-upload)[alphasnow/aliyun-oss-flysystem

Flysystem adapter for the Aliyun storage

14282.5k9](/packages/alphasnow-aliyun-oss-flysystem)

PHPackages © 2026

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