http://www.thinkphp.cn/code/3381.html
ThinkPHP 文件上传到阿里云OSS上
前往阿里云github下载SDK包:https://github.com/aliyun/aliyun-oss-php-sdk/releases。
将下载下来的压缩包解压后放到项目ThinkPHP\Library\Vendor\aliyun路径下
//本地上传至oss
public function uploadServerToOss()
{
vendor('aliyun.autoload');
$ossClient = new \OSS\OssClient("XXXXFFhV9B3orBCc","XXXXXn08fN3nI0wMnFTax0U4LygpE","oss-cn-beijing.aliyuncs.com");
$object = "hr_saas/resume/" . 'test/3s.doc';//想要保存文件的名称
$file ="/data/web/hr_sas/Public/Uploads/test/3s.doc";//文件路径,必须是本地的。
try {
$getOssInfo = $ossClient->uploadFile("XXXX-saas", $object, $file);
var_dump($getOssInfo);die();
$getOssPdfUrl = $getOssInfo['info']['url'];
if ($getOssPdfUrl) {
//unlink($file);
// rmdir($upload->rootPath.$upload->savePath,0777);
}
} catch (OssException $e) {
printf($e->getMessage() . "\n");
return;
}
echo 'over';
}