Using Alibaba Cloud OSS Composer package sharing in Laravel_PHP tutorial

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

Using Alibaba Cloud OSS Composer package sharing in Laravel

This article mainly introduces the use of Alibaba Cloud OSS Composer package sharing in Laravel. This article explains how to use it. For file downloads, please go to The github address in the file, friends in need can refer to it

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:

The code is as follows:


require: {

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

}

Then run composer update

Use

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/955837.htmlTechArticleUsing Alibaba Cloud OSS Composer package sharing in Laravel This article mainly introduces the use of Alibaba Cloud OSS Composer package sharing in Laravel , this article explains how to use it. To download the file, please go to...
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