___ __ _ ____ _____ _____
/ | / / (_) __ __ __ __ ____ / __ \ / ___/ / ___/
/ /| | / / / / / / / / / / / / / __ \ / / / / \__ \ \__ \
/ ___ | / / / / / /_/ / / /_/ / / / / / / /_/ / ___/ / ___/ /
/_/ |_|/_/ /_/ \__, / \__,_/ /_/ /_/ \____/ /____/ /____/
/____/
AliyunOSS 是阿里云 OSS 官方 SDK 的 Composer 封装,支持任何 PHP 项目,包括 Laravel、Symfony、TinyLara 等等。
- 2017-03-08
Release v2.0.0
v2 发布,在 API 易用性上进行了大量优化 - 2016-09-12
Release v1.3.5
加入文件元信息的设置功能 - 2016-07-20
Release v1.3.4
加入文件元信息的获取功能 - 2016-01-31
Release v1.3.2
获取指定虚拟文件夹下的所有文件 - 2015-10-23
Release v1.3
增加删除、复制、移动文件功能 - 2015-08-07
Release v1.2
修复内存泄露 bug - 2015-01-12
Release v1.1
增加内外网配置分离 - 2015-01-09
Release v1.0
完善功能,增加 Laravel 框架详细使用教程及代码
安装有两种方式:
将以下内容增加到 composer.json:
require: {
"johnlui/aliyun-oss": "~2.0"
}
然后运行 composer update
。
运行命令:
composer require johnlui/aliyun-oss:~2.0
新建 app/services/OSS.php
,内容可参考:OSS.php,然后修改配置:
... ...
private $city = '青岛';
// 经典网络 or VPC
private $networkType = '经典网络';
private $AccessKeyId = '';
private $AccessKeySecret = '';
... ...
在 composer.json
中 autoload -> classmap
处增加配置:
"autoload": {
"classmap": [
"app/services"
]
}
然后运行 composer dump-autoload
。
无需配置,保证目录 App/Services
和命名空间 namespace App\Services;
一致即可自动加载。
use App\Services\OSS;
// 在外网上传一个文件并指定 options 如:Content-Type 类型
// 更多 options 见:https://github.com/johnlui/AliyunOSS/blob/master/src/oss/src/Aliyun/OSS/OSSClient.php#L142-L148
OSS::publicUpload('bucket', '目标 object 名', '本地文件绝对路径', [
'ContentType' => 'application/pdf',
... ...
]);
更多用法等待着你去发现。
如果你正在使用基于 Symfony 创建的第三方应用程序,而又恰好不懂命名空间及 Composer 自动加载,那么看下面就知道本库在 Symfony 中的用法了:
新建 src/AppBundle/Services/OSS.php
,内容参考:OSS.php。
修改顶部的命名空间为 namespace AppBundle\Services;
。
无需配置。
use AppBundle\Services\OSS;
OSS::publicUpload('bucket', '目标 object 名', '本地文件绝对路径');
有问题请到 http://lvwenhan.com/laravel/425.html 下面留言。
除 “版权所有(C)阿里云计算有限公司” 的代码文件外,遵循 MIT license 开源。
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.