当前位置:网站首页>laravel8 实现阿里云文件上传
laravel8 实现阿里云文件上传
2022-06-10 21:49:00 【s_罐装冰块】
阿里云官方文档
简单上传 (aliyun.com)
https://help.aliyun.com/document_detail/88473.html1.通过composer 来下载所需插件。
下面的官方文档有我们需要的compser
composer require aliyuncs/oss-sdk-php安装 (aliyun.com)
https://help.aliyun.com/document_detail/85580.html2.在后台控制器中写入文件上传的代码。
下面的官方文档有我们需要的官方的上传代码示例
//阿里云上传
public function uploades(Request $request)
{
//获取图片值
//接收文件上传的值
$file = $request->file('image');
// 返回一个文件字符串
$path = $file->getRealPath();
$ext = $file->getClientOriginalExtension();
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
$accessKeyId = "";
$accessKeySecret = "";
// yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
$endpoint = "https://oss-cn-shanghai.aliyuncs.com";
// 填写Bucket名称,例如examplebucket。
$bucket = "";
// 填写Object完整路径,例如exampledir/exampleobject.txt。Object完整路径中不能包含Bucket名称。
$object = rand(1111, 9999) . '.' . $ext;
// <yourLocalFile>由本地文件路径加文件名包括后缀组成,例如/users/local/myfile.txt。
// 填写本地文件的完整路径,例如D:\\localpath\\examplefile.txt。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件。
$filePath = $path;
try {
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
$ossClient->uploadFile($bucket, $object, $filePath);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
// 返回上传图片路径
$imgUrl = "https://songphoto.oss-cn-shanghai.aliyuncs.com" . $object;
return ['url' => $imgUrl];
print(__FUNCTION__ . "OK" . "\n");
}简单上传 (aliyun.com)
https://help.aliyun.com/document_detail/88473.html
注:在我们使用阿里云上传的时候,需要安装认证证书。
边栏推荐
- Storage engine analysis
- Auto.js pro 开发环境配置
- Face recognition software based on deepface model
- Informatics Olympiad all in one 1280: [example 9.24] skiing | openjudge noi 2.690: skiing | Luogu p1434 [show2002] skiing
- Opencv_ 100 questions_ Chapter IV (16-20)
- 但身示你五县非那最土zaiFKMW
- Open source project PM how to design official website
- Locking mechanism
- [tcapulusdb knowledge base] tcapulusdb shard relocation introduction
- Interpreting the registry class of mmcv
猜你喜欢

Blue Bridge Cup_ Pick substring_ Combinatorial mathematics_ Multiplication principle/ Ruler method
![Authoritative guide to Web3 technology stack [2022]](/img/76/0f64604f5e5355300f5ec498ea23e1.png)
Authoritative guide to Web3 technology stack [2022]
![[XPath] use following sibling to obtain the following peer nodes](/img/f6/a30bdde45b3dcbf1fec796e4a48b23.png)
[XPath] use following sibling to obtain the following peer nodes

Missing heritability

Niuke: expression evaluation

Keras deep learning practice (8) -- using data enhancement to improve neural network performance

AI智能视频分析EasyCVR平台设备通道批量删除功能的开发实现

原生支持 ARM64 的首个版本!微软 Win11/10 免费工具集 PowerToys 0.59 发布

Play electronics, poor three generations

Auto. JS Pro development environment configuration
随机推荐
通达信股票开户安全吗?如何办理开户呢?
Several reasons and solutions of virtual machine Ping failure
Mmdetection dataloader construction
[006] initial string
IPO can't cure Weima's complications?
AI智能视频分析EasyCVR平台设备通道批量删除功能的开发实现
0223-总结
Reading notes on the way of Huawei data
聚簇索引和非聚簇索引
Thread pool: a magic weapon for managing threads
Display of successful cases of target customer matching data table
1.Tornado简介&&本专栏搭建tornado项目简介
【原创】医鹿APP九价HPV数据抓包分析
Native support for the first version of arm64! Microsoft win11/10 free tool set PowerToys 0.59 release
Locking mechanism
Is it safe for BOC securities to open an account? What is its relationship with the Bank of China?
Digital twin: third person mouse operation
Keras deep learning practice (8) -- using data enhancement to improve neural network performance
Pki/tls Swiss Army knife cfssl
IP anti query domain name