当前位置:网站首页>Laravel8 enables alicloud file upload
Laravel8 enables alicloud file upload
2022-06-10 23:08:00 【s_ Canned ice】
Official documents of Alibaba cloud
Simple upload (aliyun.com)
https://help.aliyun.com/document_detail/88473.html1. adopt composer To download the required plug-ins .
The following official documents have what we need compser
composer require aliyuncs/oss-sdk-php install (aliyun.com)
https://help.aliyun.com/document_detail/85580.html2. Write the file upload code in the background controller .
The following official documents have the official upload code examples we need
// Alicloud upload
public function uploades(Request $request)
{
// Get picture value
// Receive file upload value
$file = $request->file('image');
// Returns a file string
$path = $file->getRealPath();
$ext = $file->getClientOriginalExtension();
// Alicloud account AccessKey Have all the API Access rights of , The risk is high . It is highly recommended that you create and use it RAM The user carries out API Visit or daily operations , Please log in RAM Console creation RAM user .
$accessKeyId = "";
$accessKeySecret = "";
// yourEndpoint Fill in Bucket The region corresponding to Endpoint. East China 1( Hangzhou ) For example ,Endpoint Fill in for https://oss-cn-hangzhou.aliyuncs.com.
$endpoint = "https://oss-cn-shanghai.aliyuncs.com";
// Fill in Bucket name , for example examplebucket.
$bucket = "";
// Fill in Object The full path , for example exampledir/exampleobject.txt.Object The full path cannot contain Bucket name .
$object = rand(1111, 9999) . '.' . $ext;
// <yourLocalFile> By the local file path plus file name including suffixes , for example /users/local/myfile.txt.
// Fill in the full path of the local file , for example D:\\localpath\\examplefile.txt. If no local path is specified , By default, the file is uploaded from the local path corresponding to the project to which the sample program belongs .
$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;
}
// Return to the upload image path
$imgUrl = "https://songphoto.oss-cn-shanghai.aliyuncs.com" . $object;
return ['url' => $imgUrl];
print(__FUNCTION__ . "OK" . "\n");
} Simple upload (aliyun.com)
https://help.aliyun.com/document_detail/88473.html
notes : When we use Alibaba cloud to upload , Need to install certification certificate .
边栏推荐
- 通达信股票开户安全吗?如何办理开户呢?
- Unity code registers events for animation
- About the college entrance examination
- JS sensitive information leak detection tool
- 200个C语言单词,请收藏!
- Sdn/nfv application in cloud data center
- 分布式基础
- Digital twin: third person mouse operation
- Kubernetes binary installation (v1.20.15) (VI) deploying worknode nodes
- Pki/tls Swiss Army knife cfssl
猜你喜欢

Display of successful cases of target customer matching data table

ICML2022 | 從零開始重新審視端到端的語音到文本翻譯

分布式基础

Blue Bridge Cup_ A fool sends a letter_ recursion

Html+php+mysql login registration page

Redis数据结构
![Authoritative guide to Web3 technology stack [2022]](/img/76/0f64604f5e5355300f5ec498ea23e1.png)
Authoritative guide to Web3 technology stack [2022]

【接口教程】EasyCVR如何通过接口设置平台级联?

样板小作坊

Keras深度学习实战(8)——使用数据增强提高神经网络性能
随机推荐
Redis数据结构
Missing heritability
2022 Shanghai safety officer C certificate operation certificate examination question bank simulated examination platform operation
【原创】医鹿APP九价HPV数据抓包分析
Is there any risk in opening an account with BOC securities? Is it safe?
[play with Huawei cloud] take you through the Kunpeng code migration tool to realize source code migration
Auto.js pro 开发环境配置
开中银证券账户安全吗?风险高吗?
Mmdetection dataloader construction
Play electronics, poor three generations
Locking mechanism
Swin_ Interpretation of transformer source code
锁机制
关于String.format(String format, Object... args)
[tcapulusdb knowledge base] tcapulusdb tcapproxy capacity expansion introduction
How Photoshop opens, edits and exports pictures in webp format
Web3技术栈权威指南【2022】
vulnhub之dc4
Several reasons and solutions of virtual machine Ping failure
数据与信息资源共享平台(七)