当前位置:网站首页>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 .
边栏推荐
- [play with Huawei cloud] take you through the Kunpeng code migration tool to realize source code migration
- Multus CNI deployment and basic use of kubernetes multi network card scheme
- [Axi] explain the principle of two-way handshake mechanism of Axi protocol
- 锁机制
- 06 15 10 20 神秘代码,等你破译
- Redis from entry to entry
- 样板小作坊
- How about opening an account with flush? Is it safe to open an account?
- Display of successful cases of target customer matching data table
- kubernetes多网卡方案之Multus CNI部署和基本使用
猜你喜欢

How to run Plink software -- three methods

Multus CNI deployment and basic use of kubernetes multi network card scheme

Auto.js pro 开发环境配置

vulnhub之dc3

数据与信息资源共享平台(七)

Opencv_ 100 questions_ Chapter III (11-15)

Interpretation of dataset class of mmdetection

Redis from entry to entry

爬虫学习知识

C automatically generates Oracle table creation statement according to excel
随机推荐
Sentinel
完美解码PureCodec 20220601
数组、List、Set、Map、Properties依赖注入格式
Opencv_ 100 questions_ Chapter II (6-10)
Face recognition software based on deepface model
数据与信息资源共享平台(九)
The definition of the metauniverse and the seven infinite features
Can Huawei matepad become the secondary screen of your laptop?
Redis数据结构
集度夏一平:不是所有事都向李彦宏汇报,靠产品跟小米华为竞争
Kubernetes binary installation (v1.20.15) (VI) deploying worknode nodes
通达信股票开户安全吗?如何办理开户呢?
[original] analysis of nine price HPV data capture of Yilu app
Vscode common shortcuts
2022 Shanghai safety officer C certificate operation certificate examination question bank simulated examination platform operation
How Photoshop opens, edits and exports pictures in webp format
Watlow签订从施耐德电气手中收购Eurotherm的协议
Openjudge noi 1.13 15: finding modes in sequences
中银证券开户有什么风险吗?安全的吗?
分布式基础