第一步:下载sdk
下载地址:https://github.com/aliyun/aliyun-oss-php-sdk?spm=a2c4g.11186623.2.9.451233bc4YHDpk
第二步:
将下载下来的文件,重命名为:alioss,放在extend文件夹下面
![]()
第三步:
在application下配置文件config.php中添加
//阿里云资源服务器配置,里面填写你们自己的oss账号的相关信息
'aliyunOss'=>[
'KeyId' => '',
'KeySecret' =>'',
'Endpoint' => '',
'Bucket'=> ''
]
第四步:
编写文件上传类
<?php
namespace app\common\controller;
use think\Controller;
use think\Config;
use think\Image;
use OSS\OssClient;
use OSS\Core\OssException;
class Alioss extends Controller
{
/*
测试函数
public function index(){
return $this->fetch('user/index');
}*/
/**
* 单文件上传
* $file = request()->file('file'); //

本文介绍了如何在ThinkPHP5框架下,通过阿里云PHP SDK实现文件上传到阿里云OSS存储服务。步骤包括下载SDK、放置文件、配置应用及编写上传类。
最低0.47元/天 解锁文章
4369

被折叠的 条评论
为什么被折叠?



