当前位置:网站首页>Ueditor + PHP enables Alibaba cloud OSS upload
Ueditor + PHP enables Alibaba cloud OSS upload
2022-07-05 13:43:00 【Black hearted green rose】
One 、 install oss SDK
1. stay GitHub Select the corresponding version in and download the packaged zip file .
https://github.com/aliyun/aliyun-oss-php-sdk/releases?spm=a2c4g.11186623.2.12.544626fdfihDfy
If the link cannot be opened , You can find it on Alibaba cloud's official website
2. The extracted root directory contains a autoload.php file , Introduce this file into your code :
require_once '/path/to/oss-sdk/autoload.php';
3. Set up oss Upload method
<?Php
// quote oss
if (is_file('../autoload.php')) {
require_once ('../autoload.php');
}
use OSS\OssClient;
use OSS\Core\OssException;
/**
* Notes: Alicloud configuration Ueditor Upload
* Created by assasin.
* Request-Method: POST+AES
*/
class OssInUe
{
public function __construct(){
}
/**
* Notes: Alicloud configuration Ueditor Upload
* Created by assasin.
* Request-Method: POST+AES
*/
function uploadToAliOSS($file,$fullName){
$accessKeyId = 'xxxxxxxxxxxxxx';// Don't let it out when it comes to privacy
$accessKeySecret = 'xxxxxxxxxxxxxxxxxxxxx';// Don't let it out when it comes to privacy
$endpoint = 'xxxxxxxxxxxx';// node
$bucket= 'xxxxxxxxx';//" < You used Bucket name , Pay attention to naming conventions >";
$object = $fullName;//" < You used Object name , Pay attention to naming conventions >";
$content = $file["tmp_name"];// Uploaded files
try {
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
$ossClient->setTimeout(3600 /* seconds */);
$ossClient->setConnectTimeout(10 /* seconds */);
//$ossClient->putObject($bucket, $object, $content);
// First put the local example.jpg Upload to specified $bucket, Name it $object
$ossClient->uploadFile($bucket, $object, $content);
$signedUrl = $ossClient->signUrl($bucket, $object);
$path = explode('?',$signedUrl)[0];
$obj['status'] = true;
$obj['path'] = $path;
} catch (OssException $e) {
$obj['status'] = false;
$obj['path'] = "";
print $e->getMessage();
}
return $obj;
}
}
4. modify Uploader.class.php
Top reference oss Method , The code is about 123 That's ok , notes :
// Failed to create directory
// if ( !file_exists( $dirname ) && !mkdir( $dirname, 0777, true ) ) {
// $this->stateInfo = $this->getStateInfo( "ERROR_CREATE_DIR" );
// return;
// } else if ( !is_writeable( $dirname ) ) {
// $this->stateInfo = $this->getStateInfo( "ERROR_DIR_NOT_WRITEABLE" );
// return;
// }
//
// // Moving files
// if ( !( move_uploaded_file( $file[ "tmp_name" ], $this->filePath ) && file_exists( $this->filePath ) ) ) { // Move failed
// $this->stateInfo = $this->getStateInfo( "ERROR_FILE_MOVE" );
// } else { // Mobile success
// $this->stateInfo = $this->stateMap[ 0 ];
// }
//
// if($this->water){// watermark
// $this->watermark($this->filePath,$this->filePath);
// }
Add... At the bottom oss Upload method :
$ossInUe = new OssInUe();
$obj = $ossInUe->uploadToAliOSS($img,$this->fileType);
if ($obj['status'] == true){
$this->fullName = $obj['path'];
$this->stateInfo = $this->stateMap[0];
}else{
$this->stateInfo = $this->getStateInfo("ERROR_WRITE_CONTENT");
}
边栏推荐
- C object storage
- mysql获得时间
- Jenkins installation
- MySQL - database query - sort query, paging query
- 53. Maximum subarray sum: give you an integer array num, please find a continuous subarray with the maximum sum (the subarray contains at least one element) and return its maximum sum.
- aspx 简单的用户登录
- asp. Net read TXT file
- Primary code audit [no dolls (modification)] assessment
- 【Hot100】34. Find the first and last positions of elements in a sorted array
- leetcode 10. Regular expression matching regular expression matching (difficult)
猜你喜欢
Mmseg - Mutli view time series data inspection and visualization
Win10——轻量级小工具
[deep learning paper notes] hnf-netv2 for segmentation of brain tumors using multimodal MR imaging
The "Baidu Cup" CTF competition was held in February 2017, Web: explosion-2
RK3566添加LED
Android本地Sqlite数据库的备份和还原
Don't know these four caching modes, dare you say you understand caching?
Introduction to Chapter 8 proof problem of njupt "Xin'an numeral base"
[notes of in-depth study paper]transbtsv2: wider instead of deep transformer for medical image segmentation
What about data leakage? " Watson k'7 moves to eliminate security threats
随机推荐
The development of speech recognition app with uni app is simple and fast.
Jasypt configuration file encryption | quick start | actual combat
aspx 简单的用户登录
Primary code audit [no dolls (modification)] assessment
Aspx simple user login
MATLAB论文图表标准格式输出(干货)
什么是网络端口
redis6数据类型及操作总结
Go array and slice
Integer ==比较会自动拆箱 该变量不能赋值为空
个人组件 - 消息提示
Pancake Bulldog robot V2 (code optimized)
ETCD数据库源码分析——rawnode简单封装
Idea set method annotation and class annotation
真正的缓存之王,Google Guava 只是弟弟
asp. Net read TXT file
Binder communication process and servicemanager creation process
Win10——轻量级小工具
Jetpack Compose入门到精通
Win10 - lightweight gadget