PHPackages                             tinymeng/uploads - 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. tinymeng/uploads

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

tinymeng/uploads
================

Oss Uploads

v1.1.1(1mo ago)12652MITPHPPHP &gt;=5.4.0

Since Jun 17Pushed 1mo agoCompare

[ Source](https://github.com/majiameng/uploads)[ Packagist](https://packagist.org/packages/tinymeng/uploads)[ RSS](/packages/tinymeng-uploads/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (8)Versions (7)Used By (0)

tinymeng/uploads
================

[](#tinymenguploads)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/c8ed45e7cb548d1f7fcaea13b7d196c7072595fcf3ca210dd27c22729d382307/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d616a69616d656e672f75706c6f6164732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/majiameng/uploads/?branch=master)[![Build Status](https://camo.githubusercontent.com/7c122eb81a8e4a4cf125be28d867f9ff16ab293aa37946890c6272edeb7032ea/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d616a69616d656e672f75706c6f6164732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/majiameng/uploads/build-status/master)[![Latest Stable Version](https://camo.githubusercontent.com/b589e3cf250367c04e1667630555fdee97b8d9a5cb2f1bb23b93ab9e00efdec9/68747470733a2f2f706f7365722e707567782e6f72672f74696e796d656e672f75706c6f6164732f762f737461626c65)](https://packagist.org/packages/tinymeng/uploads)[![Total Downloads](https://camo.githubusercontent.com/087b8b9b20ce77bdadac30b612811b1b4021dc3afde02f77f14d937feccdc9e8/68747470733a2f2f706f7365722e707567782e6f72672f74696e796d656e672f75706c6f6164732f646f776e6c6f616473)](https://github.com/majiameng/uploads/tags)[![Latest Unstable Version](https://camo.githubusercontent.com/0a95aca663c3f2c0da5fd816fc65c4b9335a4aa15587680803e4c53fa7aeedf7/68747470733a2f2f706f7365722e707567782e6f72672f74696e796d656e672f75706c6f6164732f762f756e737461626c65)](https://packagist.org/packages/tinymeng/uploads)[![License](https://camo.githubusercontent.com/697b1bc7df3bb256a28fbfd1e6b22a66bf60fe2304e1df694d2bc80fba24efc7/68747470733a2f2f706f7365722e707567782e6f72672f74696e796d656e672f75706c6f6164732f6c6963656e7365)](https://github.com/majiameng/uploads/blob/master/LICENSE)

\# 通用文件上传到第三方说明文档 - oss 阿里云
- qiniu 七牛
- cos 腾讯云

### 安装

[](#安装)

```
composer require tinymeng/uploads -vvv

```

> 类库使用的命名空间为`\\tinymeng\\uploads`

### 目录结构

[](#目录结构)

```
.
├── src                              代码源文件目录
│   ├── Connector
│   │   ├── Gateway.php            必须继承的抽象类
│   │   └── GatewayInterface.php   必须实现的接口
│   ├── exception
│   │   └── TinymengException.php
│   ├── Gateways
│   │   ├── Cos.php
│   │   └── Oss.php
│   │   └── Qiniu.php
│   ├── Helper
│   │   ├── FileFunction.php
│   │   ├── MimeType.php
│   │   ├── PathLibrary.php
│   │   └── Str.php                 字符串辅助类
│   └── Upload.php                   抽象实例类
├── composer.json                    composer文件
├── LICENSE                          MIT License
└── README.md                        说明文件

```

###### 开始

[](#开始)

- use Storage

```
use Storage;

```

- 示例代码

```
        $config = [
              'accessKeyId'		=> '',
              'accessKeySecret' 	=> '',

              'isCName'			=> false,
              'securityToken'		=> null,
              'bucket'            => '',
              'endpoint'			=> '',// 阿里云地域地址，OSS必填
              'region' 	=> 'ap-beijing',// 存储桶所在地域，COS必须字段
              'timeout'           => '5184000',
              'connectTimeout'    => '10',
              'transport'     	=> 'http',//如果支持https，请填写https，如果不支持请填写http
              'max_keys'          => 1000,//max-keys用于限定此次返回object的最大数，如果不设定，默认为100，max-keys取值不能大于1000
        ];
        $drive = Upload::oss($config);
        $a = $drive->uploadFile("test6.png", $_FILES['file']['tmp_name'] );//file上传文件

        $image  = "11/22/33/7125_yangxiansen.jpg";
        $image2 = "111.png";
        $image3 = "2.txt";

        $drive = Upload::oss($config);
        $drive->write("test2.txt", "111222",$config);
        $drive->getMetadata($image2);                                                         //判断文件是否存在
        $drive->geturl($image2);                                                              //获得文件的 url
        $drive->has($image2);                                                                 //判断文件是否存在
        $drive->listContents('');                                                             //列出文件列表
        $drive->getSize($image2);                                                             //获得图片大小
        $drive->getMimetype($image2);                                                         //获得图片mime类型
        $drive->getTimestamp($image2);                                                        //获得图片上传时间戳
        $drive->read($image3);                                                                //获得文件信息
        $drive->readStream($image3);                                                          //获得文件信息
        $drive->rename($image3, '4.txt/');                                                    //重命名文件
        $drive->copy('4.txt/', '/txt/5.txt');                                                 //复制文件
        $drive->delete('/txt/5.txt');                                                         //删除文件
        $drive->write("/txt/4.txt", $drive->read("/4.txt");                                //上传文件
        $drive->write("/test2.txt", "111222");                                                //上传文件
        $drive->deleteDir('txt/');                                                            //删除文件夹
        $drive->createDir('test3/');                                                          //创建文件夹
        $handle = fopen('/tmp/email.png', 'r');
        $drive->writeStream("/write/test3.png", $handle);                                  //上传文件(文件流方式)
        $drive->writeStream("/test6.png", $drive->readStream('/write/test3.png') );         //上传文件(文件流方式)

```

> 注意：详细使用，可以参考单元测试里面的代码。

###### 配置信息

[](#配置信息)

### 方式一：使用配置文件（推荐）

[](#方式一使用配置文件推荐)

在 `vendor/tinymeng/uploads/config/TUploads.php` 中配置默认参数：

```
return [
    'default' => 'oss',  // 默认使用的存储驱动

    'oss' => [
        'accessKeyId'     => '',
        'accessKeySecret' => '',
        'endpoint'        => '',
        'bucket'          => '',
        // ... 其他配置
    ],

    'cos' => [
        'secretId'  => '',
        'secretKey' => '',
        'bucket'    => '',
        'region'    => 'ap-beijing',
        // ... 其他配置
    ],

    'qiniu' => [
        'domain'     => '',
        'access_key' => '',
        'secret_key' => '',
        'bucket'     => '',
        // ... 其他配置
    ],
];
```

使用配置文件时，可以直接调用，配置会自动加载：

```
// 使用配置文件中的默认配置
$drive = Upload::oss();

// 或者覆盖部分配置
$drive = Upload::oss(['bucket' => 'my-bucket']);
```

### 方式二：直接传入配置

[](#方式二直接传入配置)

```
// 七牛云配置
$qiniuConfig = [
    'driver'        => 'qiniu',
    'domain'        => '',//你的七牛域名
    'access_key'    => '',//AccessKey
    'secret_key'    => '',//SecretKey
    'bucket'        => '',//Bucket名字
    'transport'     => 'http',//如果支持https，请填写https，如果不支持请填写http
];

// 阿里云OSS配置
$ossConfig = [
    'accessKeyId'		=> '',
    'accessKeySecret' 	=> '',
    'endpoint'			=> '',
    'isCName'			=> false,
    'securityToken'		=> null,
    'bucket'            => '',
    'timeout'           => '5184000',
    'connectTimeout'    => '10',
    'transport'     	=> 'http',//如果支持https，请填写https，如果不支持请填写http
    'max_keys'          => 1000,//max-keys用于限定此次返回object的最大数，如果不设定，默认为100，max-keys取值不能大于1000
];

// 腾讯云COS配置
$cosConfig = [
    'secretId'	=> '',
    'secretKey' => '',
    'bucket'    => '',
    'region' 	=> 'ap-beijing',
    'isCName'			=> false,
    'securityToken'		=> null,
    'timeout'           => '5184000',
    'connectTimeout'    => '10',
    'transport'     	=> 'http',//如果支持https，请填写https，如果不支持请填写http
    'max_keys'          => 1000,//max-keys用于限定此次返回object的最大数，如果不设定，默认为100，max-keys取值不能大于1000
    // 兼容字段（会自动映射）
    'accessKeyId'       => '',  // 兼容字段，会自动映射到 secretId
    'accessKeySecret'   => '',  // 兼容字段，会自动映射到 secretKey
    'urlPrefix'         => '',  // 自定义域名前缀
];
```

### 版本修复

[](#版本修复)

2021-03-12 更新以下功能 Tag v1.0.2

```
1.增加oss上传设置元信息

可直接下载的文件
$option = [
    OssClient::OSS_CONTENT_TYPE => 'application/octet-stream',
];
$oss_upload_result = $drive->uploadFile($save_file_path, $upload_path,$option);

```

2020-11-12 更新以下功能 Tag v1.0.1

```
1.修改TinymengException异常类

```

###### 协议

[](#协议)

MIT

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance92

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Recently: every ~483 days

Total

6

Last Release

38d ago

### Community

Maintainers

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

---

Top Contributors

[![majiameng](https://avatars.githubusercontent.com/u/24783993?v=4)](https://github.com/majiameng "majiameng (19 commits)")

---

Tags

tinymengoss-uploads

### Embed Badge

![Health badge](/badges/tinymeng-uploads/health.svg)

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

PHPackages © 2026

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