当前位置:网站首页>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 .
边栏推荐
- JS sensitive information leak detection tool
- 汇编:汇编与C派系语言混用以及对应LLDB常用指令
- [tcapulusdb knowledge base] tcapulusdb tcapdb capacity expansion and contraction introduction
- "Draw the bow as strong, use the arrow as long", Manfu technology opens a new track for the data service industry
- PKI/TLS瑞士军刀之cfssl
- Niuke: expression evaluation
- 分布式基础
- Watlow签订从施耐德电气手中收购Eurotherm的协议
- Unity code registers events for animation
- js敏感信息泄露检测工具
猜你喜欢

Display of successful cases of target customer matching data table

laravel8 实现阿里云文件上传

Sherri Monroe被任命为增材制造商绿色贸易协会的新任执行董事

联想首次详解混合云Lenovo xCloud五大优势,如何打造智能化数字底座

Fallback operation in SVN

C automatically generates Oracle table creation statement according to excel

Opencv_ 100 questions_ Chapter III (11-15)

Vulnhub practice DC-1 target

Redis数据结构

Niuke.com: sum of two numbers
随机推荐
锁机制
vulnhub之DC2
06151020 mysterious code, waiting for you to decipher
Interpretation of dataset class of mmdetection
Opencv_ 100 questions_ Chapter II (6-10)
Web3技术栈权威指南【2022】
Several reasons and solutions of virtual machine Ping failure
我们对产业互联网的认识,还是困囿于互联网式的平台和中心的逻辑之中
Mmdetection dataloader construction
聚簇索引和非聚簇索引
Question bank and simulation test of 2022 tea artist (intermediate) operation certificate examination
【原创】医鹿APP九价HPV数据抓包分析
Image mosaic camera mosaic notes
Sentinel
Vscode common plug-ins and configurations
Keras深度学习实战(8)——使用数据增强提高神经网络性能
Blue Bridge Cup_ A fool sends a letter_ recursion
Reading notes on the way of Huawei data
Locking mechanism
【原创】医鹿APP九价HPV数据抓包分析