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!