百度编辑器单文件上传bug

一前端配置

  window.UEDITOR_HOME_URL = "__ROOT__/Public/static/plug/ueditor/";
    var ue;
    $(function () {
        ue = UE.getEditor('container',{
            serverUrl:"{:url('Ueditor/action')}",
            /*toolbars: [[
                'fullscreen', 'source', '|', 'undo', 'redo', '|',
                'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
                'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                'directionalityltr', 'directionalityrtl', 'indent', '|',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
                'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|','simpleupload', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
                'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
                'print', 'preview', 'searchreplace', 'drafts', 'help'
            ]],*/
            toolbars: [
                ['simpleupload']
            ],
            offsetWidth:800,
            initialFrameWidth:800,
            initialFrameHeight:800,
            imageActionName:"image",
            imageFieldName:'image',
            imageAllowFiles:[".png", ".jpg", ".jpeg", ".gif", ".bmp"],
            imageManagerActionName:"getImageList",
            imageManagerUrlPrefix:"",
        }).ready(function () {
            var that = this;
        });
        //图片上传
        var wul = $(".filePicker");
        $.each(wul, function (index, temp) {
            wc(temp);
        })
    })

1ueditor 插件路径 window.UEDITOR_HOME_URL

2serverUrl 服务器地址 serverUrl

3imageActionName 上传图片方法

二获取配置

可以看到百度编辑器加载了这个获取配置的方法,php源码包含错误,则需要修改

$config_path 则为百度编辑器后端配置路径,后端配置图片参数如图,按格式返回后不出现报错了

三图片上传

1可以看到上图,action 方法中调用了$this->image()方法处理上传图片

2腾讯云上传

    /**
     *上传图片
     * @return  mixed;
     */
    private function image()
    {
        try {
            $file = request()->file('image');
            $data = input("post.",null);
            $data['image'] = $file;
            $flag = $this->validate($data, "Upload.image");
            if (true !== $flag) {
                return $this->error($flag);
            }
            $config['upload'] = config("upload");
            $image_root= ROOT_PATH.'public'.DS.$config['upload']['tmp'];
            if(!file_exists($image_root)){
                mkdir($image_root,0777,true);
            }
            $info = $file->move($image_root);
            if ($info) {
                // 成功上传后 获取上传信息
                $file_path = str_replace('\\', '/', $info->getSaveName());
                $image_path = $image_root.$file_path;
                $tencent = config('tencent');
                $cosClient = new Client(
                    array(
                        'region'=>$tencent['region'],
                        'schema' => 'https', //协议头部,默认为http
                        'credentials'=> array(
                            'secretId'  => $tencent['secret_id'],
                            'secretKey' => $tencent['secret_key'],
                        )
                    ));
                $body = fopen($image_path,'rb');
                $user = $this->getLoginfo();
                $path = $tencent['root']."/".$user['id']."/".$info->getFilename();
                $result = $cosClient->Upload($tencent['bucket'],$path,$body);
                if(is_resource($body)) {
                    fclose($body);
                };
                unlink($image_path);
                $res_arr = objectToarray($result);
                $url = urldecode($res_arr['Location']);
                $data =  array(
                    "state" => 'SUCCESS',
                    "url" => $url,
                    "title" => '',
                    "original" => '',
                    "type" => '.jpg',
                     "size" => $info->getInfo('size'),
                );
                header("Content-type:text/html;charset=utf-8");
                echo json_encode($data,JSON_UNESCAPED_SLASHES);
            } else {
                $data =  array(
                    "state" => 'ERROR_UNKNOWN',
                    "url" => '',
                    "title" => '',
                    "original" => '',
                    "type" => '.jpg',
                    "size" => '',
                );
                header("Content-type:text/html;charset=utf-8");
                echo json_encode($data,JSON_UNESCAPED_SLASHES);
            }
        } catch (Exception $e) {
            $data =  array(
                "state" => 'ERROR_UNKNOWN',
                "url" => '',
                "title" => '',
                "original" => '',
                "type" => '.jpg',
                "size" => '',
            );
            header("Content-type:text/html;charset=utf-8");
            echo json_encode($data,JSON_UNESCAPED_SLASHES);
        }
    }

四效果

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值