PHPackages                             sogajoy/ali-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. sogajoy/ali-oss-storage

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

sogajoy/ali-oss-storage
=======================

aliyun oss filesystem storage for laravel 5+

v2.4.0(1y ago)16MITPHP

Since Dec 30Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/sogajoy/ali-oss-storage)[ Packagist](https://packagist.org/packages/sogajoy/ali-oss-storage)[ Docs](https://github.com/sogajoy/ali-oss-storage/)[ RSS](/packages/sogajoy-ali-oss-storage/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Aliyun OSS Filesystem Storage for Larevel
=========================================

[](#aliyun-oss-filesystem-storage-for-larevel)

概述
==

[](#概述)

这是一个基于Laravel文件存储Filesystem Storage开发的支持阿里云OSS的扩展包，支持Laravel 5+。您仅需要加入一些配置即可通过Laravel的Storage无缝使用阿里云OSS作为文件存储引擎。本项目主要代码来源于“jacobcyl/ali-oss-storage”提供，本人仅优化了少部分代码，如更新了支持阿里云OSS接口签名算法V4版本。

特别感谢
----

[](#特别感谢)

- [jacobcyl/ali-oss-storage](https://github.com/jacobcyl/Aliyun-oss-storage)

运行
--

[](#运行)

- Laravel 5+
- cURL extension

安装&amp;配置
---------

[](#安装配置)

1、通过composer安装:

```
    composer require sogajoy/ali-oss-storage:^2.4
```

2、在 config/app.php 文件中加入如下配置：

```
Sogajoy\AliOss\OssServiceProvider::class,
```

3、在 app/filesystems.php 文件加入如下配置:

```
'disks'=>[
    ...
    'oss' => [
            'driver'        => 'oss',
            'access_id'     => '',
            'access_key'    => '',
            'bucket'        => '',
            'endpoint'      => '', // OSS 外网节点或自定义外部域名
            //'endpoint_internal' => '', // v2.0.4 新增配置属性，如果为空，则默认使用 endpoint 配置(由于内网上传有点小问题未解决，请大家暂时不要使用内网节点上传，正在与阿里技术沟通中)
            'cdnDomain'     => '', // 如果isCName为true, getUrl会判断cdnDomain是否设定来决定返回的url，如果cdnDomain未设置，则使用endpoint来生成url，否则使用cdn
            'ssl'           =>  // true to use 'https://' and false to use 'http://'. default is false,
            'isCName'       =>  // 是否使用自定义域名,true: 则Storage.url()会使用自定义的cdn或域名生成文件url， false: 则使用外部节点生成url
            'debug'         =>
            'region'        => '',
            'signatureVersion' => '',
    ],
    ...
]
```

4、如果您的项目文件存储都为阿里云OSS，可将 app/filesystems.php默认驱动改为oss:

```
'default' => 'oss',
```

这样您将可以通过Laravel的Storage使用阿里云OSS文件存储了！

示例代码
----

[](#示例代码)

```
Storage::disk('oss'); //如果默认驱动不是oss，需指定驱动为oss

//获取指定bucket路径下的文件
Storage::files($directory);
Storage::allFiles($directory);

Storage::put('path/to/file/file.jpg', $contents); //第一个参数是目标文件路径，第二个参数是文件内容
Storage::putFile('path/to/file/file.jpg', 'local/path/to/local_file.jpg'); //从本地路径上传文件到OSS

Storage::get('path/to/file/file.jpg'); //通过路径获取文件对象
Storage::exists('path/to/file/file.jpg'); //确定文件是否存在
Storage::size('path/to/file/file.jpg'); //获取文件大小（字节）
Storage::lastModified('path/to/file/file.jpg'); //获取上次修改日期

Storage::directories($directory); //获取给定目录中的所有目录
Storage::allDirectories($directory); //获取给定目录中的所有（递归）目录

Storage::copy('old/file1.jpg', 'new/file1.jpg');   //复制文件
Storage::move('old/file1.jpg', 'new/file1.jpg');   //移动文件
Storage::rename('path/to/file1.jpg', 'path/to/file2.jpg');     //重命名文件

Storage::prepend('file.log', 'Prepended Text'); //向文件内容前追加内容
Storage::append('file.log', 'Appended Text'); //向文件内容后追加内容

Storage::delete('file.jpg');    //删除文件
Storage::delete(['file1.jpg', 'file2.jpg']);    //删除多个文件

Storage::makeDirectory($directory); //创建目录
Storage::deleteDirectory($directory); // 递归删除目录。它将删除给定目录中的所有文件，因此请谨慎使用。

Storage::putRemoteFile('target/path/to/file/jacob.jpg', 'http://example.com/jacob.jpg'); //将远程url文件上传到OSS

Storage::url('path/to/img.jpg') //获取文件url地址
```

License
-------

[](#license)

- MIT

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance49

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

499d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dc8671f92889450708eec5aeb9daad90d450270330f8410a3c33b4a2fee579a7?d=identicon)[sogajoy](/maintainers/sogajoy)

---

Top Contributors

[![sogajoy](https://avatars.githubusercontent.com/u/193050845?v=4)](https://github.com/sogajoy "sogajoy (5 commits)")

---

Tags

laravelstoragefilesystemsaliyunoss

### Embed Badge

![Health badge](/badges/sogajoy-ali-oss-storage/health.svg)

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

###  Alternatives

[jacobcyl/ali-oss-storage

aliyun oss filesystem storage for laravel 5+

523566.2k7](/packages/jacobcyl-ali-oss-storage)

PHPackages © 2026

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