kindeditor 上传图片失败,该怎么解决

WBOY
Release: 2016-06-13 11:59:39
Original
1564 people have browsed it

kindeditor 上传图片失败

本帖最后由 nxgg8 于 2014-05-29 12:44:04 编辑 编辑器版本:KindEditor 4.1.10      

php框架:ThinkPHP3.2.2

<br />    <script><br />    var editor;<br />        KindEditor.ready(function(K) {<br />            editor = K.create('textarea[name="body"]', {<br />                allowFileManager : true,<br />                urlType : 'absolute',<br />                uploadJson:'{:U('News/uploads')}',<br />            });<br />        });    <br />    </script><br />
Copy after login

这是html页面中引用编辑器配置

上传图片的时候出问题,不管是单张图片,还是批量。都会提示以下信息,返回的图片路径是正确的,图片也正常上传了,就是不能返回编辑器。
<br />    {"error":0,"url":"Uploads/Allimg/2014-05-29/5386b82a78de0.jpg"}<br />
Copy after login




php处理
<br />    public function uploads(){                <br />            $upload = new \Think\Upload();<br />            $upload->maxSize = 3145728 ;<br />            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');<br />            $upload->rootPath = './Uploads/Allimg/'; <br />            $upload->savePath = '';<br />            $info = $upload->upload();            <br />            if($info){    <br />                $img_url = '/Uploads/Allimg/'.$info['imgFile']['savepath'].$info['imgFile']['savename'];<br />                echo json_encode(array('error' => 0, 'url' => $img_url));            <br />            }else{    <br />                // $upload->getError()<br />                echo json_encode(array('error' => 1, 'message' =>'上传失败'));            <br />            }<br />        }<br />
Copy after login


------解决方案--------------------
返回 {"error":0,"url":"Uploads/Allimg/2014-05-29/5386b82a78de0.jpg"} 这样的结果
表示上传成功了

不能放到编辑器中,可能是你把代码改错了,或是返回的数据有 BOM 头
------解决方案--------------------
是不是跨域了。
------解决方案--------------------
对比一下用 Thinkphp 和不用 Thinkphp 时的差异
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template