欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Ueditor编辑器图片上传OSS

程序员文章站 2022-05-26 13:39:20
...

首先在Uploader.class.php文件下找到upFile方法,

在移动成功后执行上传方法,

 //移动文件
        if (!(move_uploaded_file($file["tmp_name"], $this->filePath) && file_exists($this->filePath))) { //移动失败
        	$this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE");
        } else { //移动成功
        	$this->stateInfo = $this->stateMap[0];
        	self::uploadFile_Oss();
        }

这个地方只需要一个文件路径,至于上传OSS的方法,可自行搜索:

    function uploadFile_Oss() {
    	//上传oss
    	require_once ROOT . '/samples/Common.php';
    	$bucket = Common::getBucketName();
    	 
    	$ossClient = Common::getOssClient();
    	if (is_null($ossClient))
    		exit(1);
    	$filePath = $this->filePath;
	//图片压缩
    	self::Img_new($filePath,800,800);
    	$ext = strrchr($filePath, ".");
    	$object = time() . rand(100, 999) . $ext;
    	try {
    		$re = $ossClient->uploadFile($bucket, $object, $filePath);
    	} catch (OssException $e) {
    		printf(__FUNCTION__ . ": FAILED\n");
    		printf($e->getMessage() . "\n");
    		return;
    	}
    	unlink($filePath);
    	$arr = array(
    			'name' => $object,
    			'pic' => $object,
    			'message' => "",
    			'path' => Config::$upload_path,
    	);
    	$result = $arr;
    	$this->fullName = $result['path']."".$result['name'];

    }
此处最重要的是
$this->fullName = $result['path']."".$result['name'];
上传后要把上传后的全路径返回,用于展示和form提交。