上传文件到阿里云OSS里,需要注意的是,文件要先传到服务器或者用本地的绝对路径。
根据文档,先安装SDK:
composer require aliyuncs/oss-sdk-php
资源名称就是Bucket列表里的名称:
文件夹列表:
上传方法放到common.php里:
//上传文件到阿里云OSS
function uploadOSS($file){
$accessKeyId = config('app.aliyunoss.accessKeyId');
$accessKeySecret = config('app.aliyunoss.accessKeySecret');
$endpoint = config('app.aliyunoss.endpoint');
// 填写Bucket名称,例如examplebucket。
$bucket = "资源名称";//上面的bucket列表里的名字,要传到哪个bucket里就填哪个名字
// 填写Object完整路径,例如exampledir/exampleobject.txt。Object完整路径中不能包含Bucket名称。
$object = "这里是阿里云OSS文件夹名字(传到这个文件夹里,图2)".str_replace('uploads','',$file);
// <yourLocalFile>由本地文件路径加文件名包括后缀组成,例如/users/local/myfile.txt。
// 填写本地文件的完整路径,例如D:\\localpath\\examplefile.txt。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件。
$filePath = Env::get('root_path') . 'public/' .$file;
try {
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
$ossClient->uploadFile($bucket, $object, $filePath);
} catch (OssException $e) {
print $e->getMessage();
}
}
然后在需要调用上传的地方调用该方法即可:
uploadOSS($image['content']);
注意:该上传没有返回值
Mysql8新增用户,mysql8配置权限,mysql8配置,mysql8配置文件 Linux命令,scp,scp命令,Linux复制 git commit git add centos git 搭建FTP,Linux FTP,禁止FTP登录ssh 上传文件,阿里云OSS上传,文件上传到OSS,OSS文件上传,OSS上传 微信支付,微信支付V3,PHP微信支付,微信nativePay支付,微信jsapi支付 微信支付,微信支付V3,PHP微信支付 bootstrap4 modal, lavarel The subversion command line tools are no longer provided by Xcode. 银联支付,tp5.1银联支付 支付宝即时到账,PHP支付宝 system libzip must be upgraded to version >= 0.11 CMake 3.0.2 or higher is required Class 'ZipArchive' not found chr() expects parameter 1 to be int php7.4 tcpdf unexpected '='