当前位置:网站首页>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");
}边栏推荐
- The development of speech recognition app with uni app is simple and fast.
- Win10 - lightweight gadget
- 多人合作项目查看每个人写了多少行代码
- [server data recovery] a case of RAID5 data recovery stored in a brand of server
- The "Baidu Cup" CTF competition was held in February 2017, Web: explosion-2
- Intranet penetration tool NetApp
- redis6数据类型及操作总结
- 面试官灵魂拷问:为什么代码规范要求 SQL 语句不要过多的 join?
- 49. 字母异位词分组:给你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。 字母异位词 是由重新排列源单词的字母得到的一个新单词,所有源单词中的字母通常恰好只用一次。
- Pancake Bulldog robot V2 (code optimized)
猜你喜欢

Android本地Sqlite数据库的备份和还原

今年上半年,通信行业发生了哪些事?

Idea remote debugging agent

What about data leakage? " Watson k'7 moves to eliminate security threats

Cloudcompare - point cloud slice

Usage, installation and use of TortoiseSVN

jenkins安装

Datapipeline was selected into the 2022 digital intelligence atlas and database development report of China Academy of communications and communications

Could not set property 'ID' of 'class xx' with value 'XX' argument type mismatch solution

Introduction to Chapter 8 proof problem of njupt "Xin'an numeral base"
随机推荐
“百度杯”CTF比赛 九月场,Web:Upload
那些考研后才知道的事
Can and can FD
Matlab paper chart standard format output (dry goods)
leetcode 10. Regular Expression Matching 正则表达式匹配 (困难)
Backup and restore of Android local SQLite database
Talk about seven ways to realize asynchronous programming
Redis6 master-slave replication and clustering
Idea remote debugging agent
Zhubo Huangyu: these spot gold investment skills are not really bad
这18个网站能让你的页面背景炫酷起来
[深度学习论文笔记]TransBTSV2: Wider Instead of Deeper Transformer for Medical Image Segmentation
What about data leakage? " Watson k'7 moves to eliminate security threats
真正的缓存之王,Google Guava 只是弟弟
嵌入式软件架构设计-消息交互
go 数组与切片
“百度杯”CTF比赛 九月场,Web:SQL
Jenkins installation
如何把大的‘tar‘存档文件分割成特定大小的多个文件
什么叫做信息安全?包含哪些内容?与网络安全有什么区别?