Home > php教程 > php手册 > body text

Laravel中使用阿里云OSS Composer包分享,laraveloss

WBOY
Release: 2016-06-13 09:15:02
Original
1825 people have browsed it

Laravel中使用阿里云OSS Composer包分享,laraveloss

阿里云提供了基于命名空间的 V2 版 SDK,但是文档不是很完整,使用门槛比较高,于是我封装了一个 Composer 包:https://github.com/johnlui/AliyunOSS

安装

将以下内容增加到 composer.json:

复制代码 代码如下:


require: {

    "johnlui/aliyun-oss": "dev-master"

}

然后运行 composer update

使用

复制代码 代码如下:


use JohnLui\AliyunOSS\AliyunOSS;


// 构建 OSSClient 对象
// 三个参数:服务器地址、阿里云提供的AccessKeyId、AccessKeySecret
$oss = AliyunOSS::boot('http://oss-cn-qingdao.aliyuncs.com',  $AccessKeyId, $AccessKeySecret);

// 设置 Bucket
$oss = $oss->setBucket($bucketName);

// 上传一个文件(示例文件为 public 目录下的 robots.txt)
// 两个参数:资源名称、文件路径
$oss->uploadFile('robots.txt', public_path('robots.txt'));

// 从服务器获取这个资源的 URL 并打印
// 两个参数:资源名称、过期时间
echo $oss->getUrl('robots.txt', new DateTime("+1 day"));

就是这么简单,喜欢可以去 Github 上 Star 哦!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!