tp5 用 oss文件上傳

首先用 composer require aliyuncs/oss-sdk-php安裝插件javascript

而後在入口文件加入php

require_once __DIR__ .'/../vendor/aliyuncs/oss-sdk-php/autoload.php';

在文件上傳類 File.php中添加一個方法java

必須引入這倆文件composer

use OSS\OssClient;
use OSS\Core\OssException;
Public function moveOss($accessKeyId,$accessKeySecret,$endpoint,$bucket,$object,$content)
{
try {
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
$res= $ossClient->putObject($bucket, $object, $content);
} catch (OssException $e) {
print $e->getMessage();
}
return $res['info']['url'];
}

控制器ui

 

class Img extends Controller
{
public function index()
{
return view('add');
}
public function insert()
{
$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;
}
}

 

 

composer require aliyuncs/oss-sdk-php
相關文章
相關標籤/搜索