Ueditor百度编辑器上传图片显示“服务器返回出错”或返回0 但是图片上传成功了

我的解决办法.与js无关.具体看注释

```php
一,上传时,先调用了这一个文件.
Application\Core\Controller\FileController.class.php
//FileController文件内容为:
  /**用于兼容UM编辑器的图片上传方法
     * @auth 陈一枭
     */
    public function uploadPictureUM()
    {
        header("Content-Type:text/html;charset=utf-8");
        //TODO: 用户登录检测
        /* 返回标准数据 */
        $return = array('status' => 1, 'info' => L('_SUCCESS_UPLOAD_'), 'data' => '');

        //实际有用的数据只有name和state,这边伪造一堆数据保证格式正确
        $originalName = 'u=2830036734,2219770442&fm=21&gp=0.jpg';
        $newFilename = '14035912861705.jpg';
        $filePath = 'upload\/20140624\/14035912861705.jpg';
        $size = '7446';
        $type = '.jpg';
        $status = 'success';
        $rs = array(
            "originalName" => $originalName,
            'name' => $newFilename,
            'url' => $filePath,
            'size' => $size,
            'type' => $type,
            'state' => $status,
            'original' => $_FILES['upfile']['name']
        );
        /* 调用文件上传组件上传文件 */
        $Picture = D('Admin/Picture');//这里调用另一个文件
	//自动保存到缓存目录中,然后,去查看所有打印的东西,不需要时,注意注释掉

        $setting = C('EDITOR_UPLOAD');
        $setting['rootPath']='./Uploads/Editor/Picture/';

        $driver = modC('PICTURE_UPLOAD_DRIVER','local','config');
        $driver = check_driver_is_exist($driver);
        $uploadConfig = get_upload_config($driver);

        $info = $Picture->upload(
            $_FILES,
            $setting,
            $driver,
            $uploadConfig
        ); //TODO:上传到远程服务器

        /* 记录图片信息 */
        if ($info) {
            $return['status'] = 1;
            if ($info['Filedata']) {
                $return = array_merge($info['Filedata'], $return);
            }
            if ($info['download']) {
                $return = array_merge($info['download'], $return);
            }
            $rs['state'] = 'SUCCESS';
            $rs['url'] = $info['upfile']['path'];
            if ($type == 'ajax') {
                echo json_encode($rs);
                exit;
            } else {
                echo json_encode($rs);
                exit;
            }

        } else {
            $return['state'] = 0;
            $return['info'] = $Picture->getError();
        }

        /* 返回JSON数据 */
		//print_r($return);exit;
        $this->ajaxReturn($return);
    },然后再调用这个文件
Application\Admin\Model\PictureModel.class.php
//unset($info[$key]);//注释掉这一句,上传就就正常了.
原因应该是这里调用了后面的方法,但是没通过$this->create($value) && ($id = $this->add(),具体原因就不去查了.

PictureModel的文件内容为:
   /**
     * 文件上传
     * @param  array  $files   要上传的文件列表(通常是$_FILES数组)
     * @param  array  $setting 文件上传配置
     * @param  string $driver  上传驱动名称
     * @param  array  $config  上传驱动配置
     * @return array           文件上传成功后的信息
     */
    public function upload($files, $setting, $driver = 'local', $config = null){
        /* 上传文件 */
        $setting['callback'] = array($this, 'isFile');
		$setting['removeTrash'] = array($this, 'removeTrash');
        $Upload = new Upload($setting, $driver, $config);

        foreach ($files as $key => $file) {
            $ext = strtolower($file['ext']);
            if(in_array($ext, array('jpg','jpeg','bmp','png'))){
                hook('dealPicture',$file['tmp_name']);
            }
        }

        $info   = $Upload->upload($files);

        if($info){ //文件上传成功,记录文件信息
            foreach ($info as $key => &$value) {
                /* 已经存在文件记录 */
                if(isset($value['id']) && is_numeric($value['id'])){
                    continue;
                }

                /* 记录文件信息 */
                if(strtolower($driver)=='sae'){
                    $value['path'] = $config['rootPath'].'Picture/'.$value['savepath'].$value['savename']; //在模板里的url路径
                }else{
                    if(strtolower($driver) != 'local'){
                        $value['path'] =$value['url'];
                    }
                    else{
                        $value['path'] = (substr($setting['rootPath'], 1).$value['savepath'].$value['savename']);	//在模板里的url路径
                    }

                }

                $value['type'] = $driver;

                if($this->create($value) && ($id = $this->add())){
					
						//$cache='2.txt';//增加这两句,查看错误提示
   //  file_put_contents($cache,serialize($info[$key])."\n\r",FILE_APPEND);
                    $value['id'] = $id;
                } else {
                    //TODO: 文件上传成功,但是记录文件信息失败,需记录日志
	 //  unset($info[$key]);//注释掉这一句就正常了.
                }
            }

            foreach($info as &$t_info){
                if($t_info['type'] =='local'){
                    $t_info['path']=get_pic_src($t_info['path']);
                }
                else{
                    $t_info['path']=$t_info['path'];
                }
            }
          /*  dump(getRootUrl());
            dump($info);
            exit;*/

            return $info; //文件上传成功
        } else {
            $this->error = $Upload->getError();
			
			
	 
	 
            return false;
        }
    }




  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
UEditor编辑器存在一个高危漏洞,即在抓取远程数据源时未对文件后缀名做验证,导致任意文件写入漏洞。黑客可以利用这个漏洞,在服务器上执行任意指令。这个漏洞只影响.NET版本的UEditor,其他版本暂时不受影响。 为了利用这个漏洞,黑客可以在UEditor编辑器中的shell地址处填写服务器上的图片马地址,构造成特定格式。例如,在URL中将图片马地址后缀更改为.aspx,绕过上传使其解析为aspx文件,从而达到任意文件上传的目的。 为了防止这个漏洞被利用,建议开发者及时更新UEditor编辑器的最新版本,并确保在抓取远程数据源时对文件后缀名进行验证。此外,也可以限制用户上传的文件类型和大小,加强服务器的安全配置,以减少潜在的风险。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Ueditor编辑器任意文件上传漏洞](https://blog.csdn.net/m0_51468027/article/details/126077427)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Django集成百度富文本编辑器uEditor攻略](https://download.csdn.net/download/weixin_38613154/14865210)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值