当前位置:网站首页>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");
}边栏推荐
- Parsing XML using Dom4j
- [public class preview]: basis and practice of video quality evaluation
- MySQL - database query - sort query, paging query
- stm32逆向入门
- [深度学习论文笔记]使用多模态MR成像分割脑肿瘤的HNF-Netv2
- [notes of in-depth study paper]uctransnet: rethink the jumping connection in u-net from the perspective of transformer channel
- Prefix, infix, suffix expression "recommended collection"
- FPGA 学习笔记:Vivado 2019.1 添加 IP MicroBlaze
- Record in-depth learning - some bug handling
- Redis6 master-slave replication and clustering
猜你喜欢
![[server data recovery] a case of RAID5 data recovery stored in a brand of server](/img/04/c9bcf883d45a1de616c4e1b19885a5.png)
[server data recovery] a case of RAID5 data recovery stored in a brand of server

【华南理工大学】考研初试复试资料分享

Go array and slice

Shandong University Summer Training - 20220620

French scholars: the explicability of counter attack under optimal transmission theory

Flutter 3.0更新后如何应用到小程序开发中

redis6事务和锁机制

zabbix 监控

ELFK部署

When using Tencent cloud for the first time, you can only use webshell connection instead of SSH connection.
随机推荐
研究生可以不用学英语?只要考研英语或六级分数高!
Fragmented knowledge management tool memos
Solve the problem of "unable to open source file" xx.h "in the custom header file on vs from the source
【 script secret pour l'utilisation de MySQL 】 un jeu en ligne sur l'heure et le type de date de MySQL et les fonctions d'exploitation connexes (3)
Apicloud studio3 WiFi real machine synchronization and WiFi real machine preview instructions
Mmseg - Mutli view time series data inspection and visualization
Flutter 3.0更新后如何应用到小程序开发中
go 指针
go map
Pancake Bulldog robot V2 (code optimized)
Win10——轻量级小工具
先写API文档还是先写代码?
The real king of caching, Google guava is just a brother
【Hot100】34. Find the first and last positions of elements in a sorted array
Get you started with Apache pseudo static configuration
Resttemplate details
如何把大的‘tar‘存档文件分割成特定大小的多个文件
私有地址有那些
Idea set method annotation and class annotation
Huawei push service content, read notes