Ueditor编辑器图片上传OSS

首先在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提交。



猜你喜欢

转载自blog.csdn.net/y18749247391/article/details/79915418