Home  >  Article  >  Backend Development  >  codeigniter整合xheditor之后,xheditor上图片问题

codeigniter整合xheditor之后,xheditor上图片问题

WBOY
WBOYOriginal
2016-06-23 13:54:03865browse

xheditor是一款留言板插件,本身带有图片上传功能,需要把Imgurl指向到ci的控制器,但是控制器里怎么写相关代码呢,我直接用了ci的上传类和图片缩放,但是xheditor上传图片总是提示没有选择图片,网上没有详细教程,不知道我这边错误出在哪里,虚心请教


回复讨论(解决方案)

我认为应该把editor的编辑器上传url配成ci的上传action就ok了呀

我认为应该把editor的编辑器上传url配成ci的上传action就ok了呀


是的 我修改了 但是提示没有选择文件
下面是代码
内容:

是editor配置文件配置的吗/

是editor配置文件配置的吗/



是xheditor,我看xh的官方手册说
上传的话要配置upImgurl=‘’  地址我配置是ci控制器里面一个方法,方法里面写的ci的上传类,但是在前台xheditor编辑框插入图片后显示你没有选择文件的提示,xheditor官方demo8是有一个默认的upload.php,直接用它可以上传成功,但是由于ci框架的路径问题图片无法正常显示,要怎么写控制器里面的代码呢?

控制器不仅要写显示代码,还要返回浏览图片的路径呀。

我知道怎么写返回路径到xheditor里面,你用过xheditor吗,可以帮帮我吗

这是前台部分
nbsp;html>


 
<script>"></script>
<script>"></script>
<script>"></script>


' method='post'>
内容:






下面是控制器article的方法do_upload(){
$config['upload_path'] = './uploads/';
  $config['allowed_types'] = 'gif|jpg|png|jpeg';
  $config['max_size'] = '100000';
   $this->load->library('upload', $config);
if ( ! $this->upload->do_upload(‘filedata’))
  {
    $this->upload->display_errors();
}
然后你在前台用xheditor编辑框上传图片的时候会提示你未选择文件!  不知哪的问题,xheditor本身demo里面带有一个uplaod.php文件,我如果把upImgurl换成它,可以上传,但由于ci框架路径问题在xh编辑框里无法正常显示图片,这do_upload方法里面的代码要如何修改呢

??????????????????????????????????????????
这是xh默认demo里面upload.php的代码
/*!
* upload demo for php
* @requires xhEditor

* @author Yanis.Wang
* @site http://xheditor.com/
* @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php)

* @Version: 0.9.6 (build 111027)

* 注1:本程序仅为演示用,请您务必根据自己需求进行相应修改,或者重开发
* 注2:本程序特别针对HTML5上传,加入了特殊处理
*/
header('Content-Type: text/html; charset=UTF-8');

$inputName='filedata';//表单文件域name
$attachDir='upload';//上传文件保存路径,结尾不要带/
$dirType=1;//1:按天存入目录 2:按月存入目录 3:按扩展名存目录  建议使用按天存
$maxAttachSize=2097152;//最大上传大小,默认是2M
$upExt='txt,rar,zip,jpg,jpeg,gif,png,swf,wmv,avi,wma,mp3,mid';//上传扩展名
$msgType=2;//返回上传参数的格式:1,只返回url,2,返回参数数组
$immediate=isset($_GET['immediate'])?$_GET['immediate']:0;//立即上传模式,仅为演示用
ini_set('date.timezone','Asia/Shanghai');//时区

$err = "";
$msg = "''";
$tempPath=$attachDir.'/'.date("YmdHis").mt_rand(10000,99999).'.tmp';
$localName='';

if(isset($_SERVER['HTTP_CONTENT_DISPOSITION'])&&preg_match('/attachment;\\s+name="(.+?)";\\s+filename="(.+?)"/i',$_SERVER['HTTP_CONTENT_DISPOSITION'],$info)){//HTML5上传
        file_put_contents($tempPath,file_get_contents("php://input"));
        $localName=urldecode($info[2]);
}
else{//标准表单式上传
        $upfile=@$_FILES[$inputName];
        if(!isset($upfile))$err='文件域的name错误';
        elseif(!empty($upfile['error'])){
                switch($upfile['error'])
                {
                        case '1':
                                $err = '文件大小超过了php.ini定义的upload_max_filesize值';
                                break;
                        case '2':
                                $err = '文件大小超过了HTML定义的MAX_FILE_SIZE值';
                                break;
                        case '3':
                                $err = '文件上传不完全';
                                break;
                        case '4':
                                $err = '无文件上传';
                                break;
                        case '6':
                                $err = '缺少临时文件夹';
                                break;
                        case '7':
                                $err = '写文件失败';
                                break;
                        case '8':
                                $err = '上传被其它扩展中断';
                                break;
                        case '999':
                        default:
                                $err = '无有效错误代码';
                }
        }
        elseif(empty($upfile['tmp_name']) || $upfile['tmp_name'] == 'none')$err = '无文件上传';
        else{
                move_uploaded_file($upfile['tmp_name'],$tempPath);
                $localName=$upfile['name'];
        }
}

if($err==''){
        $fileInfo=pathinfo($localName);
        $extension=$fileInfo['extension'];
        if(preg_match('/^('.str_replace(',','|',$upExt).')$/i',$extension))
        {
                $bytes=filesize($tempPath);
                if($bytes > $maxAttachSize)$err='请不要上传大小超过'.formatBytes($maxAttachSize).'的文件';
                else
                {
                        switch($dirType)
                        {
                                case 1: $attachSubDir = 'day_'.date('ymd'); break;
                                case 2: $attachSubDir = 'month_'.date('ym'); break;
                                case 3: $attachSubDir = 'ext_'.$extension; break;
                        }
                        $attachDir = $attachDir.'/'.$attachSubDir;
                        if(!is_dir($attachDir))
                        {
                                @mkdir($attachDir, 0777);
                                @fclose(fopen($attachDir.'/index.htm', 'w'));
                        }
                        PHP_VERSION                          $newFilename=date("YmdHis").mt_rand(1000,9999).'.'.$extension;
                        $targetPath = $attachDir.'/'.$newFilename;
                        
                        rename($tempPath,$targetPath);
                        @chmod($targetPath,0755);
                        $targetPath=jsonString($targetPath);
                        if($immediate=='1')$targetPath='!'.$targetPath;
                        if($msgType==1)$msg="'$targetPath'";
                        else $msg="{'url':'".$targetPath."','localname':'".jsonString($localName)."','id':'1'}";//id参数固定不变,仅供演示,实际项目中可以是数据库ID
                }
        }
        else $err='上传文件扩展名必需为:'.$upExt;

        @unlink($tempPath);
}

echo "{'err':'".jsonString($err)."','msg':".$msg."}";


function jsonString($str)
{
        return preg_replace("/([\\\\\\\\\\/'])/",'\\\\\\$1',$str);
}
function formatBytes($bytes) {
        if($bytes >= 1073741824) {
                $bytes = round($bytes / 1073741824 * 100) / 100 . 'GB';
        } elseif($bytes >= 1048576) {
                $bytes = round($bytes / 1048576 * 100) / 100 . 'MB';
        } elseif($bytes >= 1024) {
                $bytes = round($bytes / 1024 * 100) / 100 . 'KB';
        } else {
                $bytes = $bytes . 'Bytes';
        }
        return $bytes;
}
?>

问题可能是这样的,你使用的是 HTML5 的上传方式,而 ci 的上传类并不支持
你可以用低版本的 IE 调试你的程序,如果能上传成功,则需要在ci 的上传类中加入 HTML5 上传功能
方法在 uplaod.php 中
如果不能成功,就算我没说

问题可能是这样的,你使用的是 HTML5 的上传方式,而 ci 的上传类并不支持
你可以用低版本的 IE 调试你的程序,如果能上传成功,则需要在ci 的上传类中加入 HTML5 上传功能
方法在 uplaod.php 中
如果不能成功,就算我没说


xuzuning  谢谢你的解答 确实如你所说,我把xheditor的html5上传关闭之后,图片可以正常上传了,但是图片无法在编辑框里正常显示,是个叉子,是图片上传成功后返回路径问题,我不知道咋写,能麻烦你按照我贴出来的xheditor  demo代码简单的提示一下嘛,再次感谢 

我找到了办法 具体要看xh的代码 里面有个echo 的json数据 按照它的规格来写就可以完美解决

Statement:
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