Home > Backend Development > PHP Tutorial > Using Alibaba Cloud OSS Composer package sharing in Laravel, laraveloss_PHP tutorial

Using Alibaba Cloud OSS Composer package sharing in Laravel, laraveloss_PHP tutorial

WBOY
Release: 2016-07-13 10:07:13
Original
1355 people have browsed it

Using Alibaba Cloud OSS Composer package sharing in Laravel, laraveloss

Alibaba Cloud provides the V2 version of the SDK based on the namespace, but the documentation is not very complete and the usage threshold is relatively high, so I packaged a Composer package: https://github.com/johnlui/AliyunOSS

Installation

Add the following content to composer.json:

Copy code The code is as follows:

require: {

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

}

Then run composer update

Use

Copy code The code is as follows:

use JohnLuiAliyunOSSAliyunOSS;


//Construct OSSClient object
// Three parameters: server address, AccessKeyId provided by Alibaba Cloud, AccessKeySecret
$oss = AliyunOSS::boot('http://oss-cn-qingdao.aliyuncs.com', $AccessKeyId, $AccessKeySecret);

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

// Upload a file (the example file is robots.txt in the public directory)
//Two parameters: resource name, file path
$oss->uploadFile('robots.txt', public_path('robots.txt'));

// Get the URL of this resource from the server and print it
// Two parameters: resource name, expiration time
echo $oss->getUrl('robots.txt', new DateTime("+1 day"));

It’s that simple. If you like it, you can star it on Github!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/955971.htmlTechArticleUsing Alibaba Cloud OSS Composer package sharing in Laravel, laraveloss Alibaba Cloud provides a V2 version of the SDK based on the namespace, but The documentation is not very complete and the threshold for use is relatively high, so I packaged it...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template