First Usecomposer require aliyuncs/oss-sdk-php安装插件
Then join in the portal file
. '/.. /vendor/aliyuncs/oss-sdk-php/autoload.php ';
Add a method to the file upload class file.php
These two files must be introduced.
OSS \ ossclient ;
OSS \ Core \ ossexception ;
Public functionMoveoss($accessKeyId,$accessKeySecret,$endpoint,$bucket,$object,$content)
{
Try{
$ossClient= Newossclient($accessKeyId, $accessKeySecret, $endpoint);
$res= $ossClient -PutObject($bucket, $object, $content);
} Catch(ossexception$e) {
Print$e -GetMessage();
}
return$res[' Info '][' URL '];
}
Controller
classImgextendsController
{
Public functionIndex()
{
returnView(' Add ');
}
Public functionInsert()
{
$file= Request() -file(' img ');
$img=$file -GetInfo();
$object="images/".$img[' name '];
$content=file_get_contents($img[' Tmp_name ']);
$info=$file -Moveoss(' Ltaiykanpiug9wai ',' Zsjpmzwxdhktss5m51uzgeoixn3zxd ',
' http://oss-cn-beijing.aliyuncs.com ',' yan0208 ',$object,$content);
Echo$info;
}
}
require aliyuncs/oss-sdk-php
TP5 uploading with OSS files