Aliyun OSS Composer package sharing _php tips in Laravel

Source: Internet
Author: User
Tags aliyun

Aliyun provides a V2 version of the SDK based on the namespace, but the document is not complete and the threshold is high, so I encapsulated a Composer package: Https://github.com/johnlui/AliyunOSS

Installation

Add the following content to the Composer.json:

Copy Code code as follows:

Require: {

"Johnlui/aliyun-oss": "Dev-master"

}

Then run composer update

Use

Copy Code code as follows:

Use Johnlui\aliyunoss\aliyunoss;


Building Ossclient Objects
Three parameters: Server address, Aliyun provided Accesskeyid, Accesskeysecret
$oss = Aliyunoss::boot (' http://oss-cn-qingdao.aliyuncs.com ', $AccessKeyId, $AccessKeySecret);

Set Bucket
$oss = $oss->setbucket ($bucketName);

Upload a file (sample file is robots.txt under the public directory)
Two parameters: Resource Name, file path
$oss->uploadfile (' robots.txt ', Public_path (' robots.txt '));

Get the URL for this resource from the server and print
Two parameters: Resource name, Expiration time
echo $oss->geturl (' robots.txt ', New DateTime ("+1 Day"));

It is so simple, like to go to Github on Star Oh!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.