Javascript CKEditor复制/粘贴上载但未在编辑器中显示的图像

Javascript CKEditor复制/粘贴上载但未在编辑器中显示的图像,javascript,php,file-upload,ckeditor,Javascript,Php,File Upload,Ckeditor,我尝试了自定义上传器的CKEditor和它的工作良好,如果我们上传图像通过默认的CKEditor文件管理器按钮,但当我复制和粘贴图像从Word图像上传,但确实显示在编辑器 这是我上传的代码 function ck_upload() { $upload_dir = array( 'img'=> '/GeneralUploads/ckUploads', ); $imgset = array(

我尝试了自定义上传器的CKEditor和它的工作良好,如果我们上传图像通过默认的CKEditor文件管理器按钮,但当我复制和粘贴图像从Word图像上传,但确实显示在编辑器

这是我上传的代码

 function ck_upload()
        {


        $upload_dir = array(
            'img'=> '/GeneralUploads/ckUploads',
        );

        $imgset = array(
            // 'maxsize' => 2000,    
            // 'maxwidth' => 900,    
            // 'maxheight' => 800,    
            'minwidth' => 10,      
            'minheight' => 10,
            'type' => array('bmp', 'gif', 'jpg', 'jpeg', 'png'),
        );

        // If 0, will OVERWRITE the existing file
        define('RENAME_F', 1);

        $re = '';
        if(isset($_FILES['upload']) && strlen($_FILES['upload']['name']) >1) {
            define('F_NAME', preg_replace('/\.(.+?)$/i', '', basename($_FILES['upload']['name'])));  //get filename without extension

            // get protocol and host name to send the absolute image path to CKEditor    
            $site = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'].'/';
            $sepext = explode('.', strtolower($_FILES['upload']['name']));
            $type = end($sepext);    // gets extension
            $upload_dir = in_array($type, $imgset['type']) ? $upload_dir['img'] : $upload_dir['audio'];
            $upload_dir = trim($upload_dir, '/') .'/';

            //checkings for image or audio
            if(in_array($type, $imgset['type'])){
                // list($width, $height) = getimagesize($_FILES['upload']['tmp_name']);  // image width and height
                if(isset($width) && isset($height)) {
                    if($width > $imgset['maxwidth'] || $height > $imgset['maxheight']) $re .= '\\n Width x Height = '. $width .' x '. $height .' \\n The maximum Width x Height must be: '. $imgset['maxwidth']. ' x '. $imgset['maxheight'];
                    if($width < $imgset['minwidth'] || $height < $imgset['minheight']) $re .= '\\n Width x Height = '. $width .' x '. $height .'\\n The minimum Width x Height must be: '. $imgset['minwidth']. ' x '. $imgset['minheight'];
                    if($_FILES['upload']['size'] > $imgset['maxsize']*1000) $re .= '\\n Maximum file size must be: '. $imgset['maxsize']. ' KB.';
                }
            }

            else $re .= 'The file: '. $_FILES['upload']['name']. ' has not the allowed extension type.';

            //set filename; if file exists, and RENAME_F is 1, set "img_name_I"
            // $p = dir-path, $fn=filename to check, $ex=extension $i=index to rename
            function setFName($p, $fn, $ex, $i){
                if(RENAME_F ==1 && file_exists($p .$fn .$ex)) return setFName($p, F_NAME .'_'. ($i +1), $ex, ($i +1));
                else return $fn .$ex;
            }

            $f_name = setFName($_SERVER['DOCUMENT_ROOT'] .'/'. $upload_dir, F_NAME, ".$type", 0);
            $uploadpath = $_SERVER['DOCUMENT_ROOT'] .'/'. $upload_dir . $f_name;  // full file path

            // If no errors, upload the image, else, output the errors
            if($re == '') {
                // print_r($_FILES);exit;
                if(move_uploaded_file($_FILES['upload']['tmp_name'], $uploadpath)) {

                    $CKEditorFuncNum = $_GET['CKEditorFuncNum'];

                      $url = $site. $upload_dir . $f_name;
                    $msg = F_NAME .'.'. $type .' successfully uploaded: \\n- Size: '. number_format($_FILES['upload']['size']/1024, 2, '.', '') .' KB';
                    $re = in_array($type, $imgset['type']) ? "window.parent.CKEDITOR.tools.callFunction($CKEditorFuncNum, '$url', '$msg')"  //for img

                   : 'var cke_ob = window.parent.CKEDITOR; for(var ckid in cke_ob.instances) { if(cke_ob.instances[ckid].focusManager.hasFocus) break;} cke_ob.instances[ckid].insertHtml(\'<audio src="'. $url .'" controls></audio>\', \'unfiltered_html\'); alert("'. $msg .'"); var dialog = cke_ob.dialog.getCurrent();  dialog.hide();';
                    print_r($re);
                }
                else $re = 'alert("Unable to upload the file")';
            }
            else $re = 'alert("'. $re .'")';
        }

        @header('Content-type: text/html; charset=utf-8');
        echo '<script>'. $re .';</script>';
}
函数ck_upload()
{
$upload\U dir=数组(
'img'=>'/GeneralUploads/ckUploads',
);
$imgset=array(
//“最大尺寸”=>2000,
//“最大宽度”=>900,
//“最大高度”=>800,
“最小宽度”=>10,
“最小高度”=>10,
'type'=>array('bmp','gif','jpg','jpeg','png'),
);
//如果为0,将覆盖现有文件
定义('RENAME_F',1);
$re='';
如果(isset($_文件['upload'])和&strlen($_文件['upload']['name'])>1){
define('F_NAME',preg_replace('/\.(.+?)$/i','',basename($\u FILES['upload']['NAME']));//获取不带扩展名的文件名
//获取协议和主机名以将绝对映像路径发送到CKEditor
$site='http'。(isset($服务器['HTTPS'])?'s':''。$服务器['http\u主机]./';
$sepext=explode('.',strtolower($_文件['upload']['name']);
$type=end($sepext);//获取扩展名
$upload_dir=在_数组中($type,$imgset['type'])?$upload_dir['img']:$upload_dir['audio'];
$upload_dir=trim($upload_dir,“/”)。/”;
//检查图像或音频
if(在数组中($type,$imgset['type'])){
//list($width,$height)=getimagesize($_文件['upload']['tmp_名称]]);//图像宽度和高度
if(isset($宽度)和isset($高度)){
如果($width>$imgset['maxwidth'].$height>$imgset['maxheight'])$re.='\\n width x height=.$width.'x'.$height.\\n最大宽度x高度必须为:'.$imgset['maxwidth'.'x'$imgset['maxheight'];
如果($width<$imgset['minwidth'].$height<$imgset['minheight'])$re.='\\n width x height='.$width.'x'.$height.\\n最小宽度x高度必须为:'.$imgset['minwidth'.'x'$imgset['minheight'];
如果($_FILES['upload']['size']>$imgset['maxsize']*1000)$re.='\\n最大文件大小必须为:'.$imgset['maxsize'].'KB';
}
}
else$re.='文件:'.$\u文件['upload']['name'].'没有允许的扩展名类型';
//设置文件名;如果文件存在且重命名为1,则设置“img\u name\u I”
//$p=目录路径,$fn=要检查的文件名,$ex=扩展名$i=要重命名的索引
函数setFName($p,$fn,$ex,$i){
如果(RENAME_F==1&&file_存在($p.$fn.$ex))返回setFName($p,F_NAME.''($i+1),$ex,($i+1));
否则返回$fn.$ex;
}
$f_name=setFName($_SERVER['DOCUMENT_ROOT']./'.$upload_dir,f_name,“.$type”,0);
$uploadpath=$\u服务器['DOCUMENT\u ROOT']./'.$UPLOADU dir.$f\u name;//完整文件路径
//如果没有错误,上传图像,否则输出错误
如果($re=''){
//打印($_文件);退出;
如果(移动上传的文件($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\$uploadpath)){
$CKEditorFuncNum=$\u GET['CKEditorFuncNum'];
$url=$site.$upload\u dir.$f\u name;
$msg=F_NAME.'.$type.'已成功上载:\\n-大小:'.number_格式($_文件['upload']['Size']/1024,2,'.'.','')。'KB';
$re=in_数组($type,$imgset['type'])?“window.parent.CKEDITOR.tools.callFunction($CKEditorFuncNum,$url','$msg')”//用于img
:'var cke_ob=window.parent.CKEDITOR;for(cke_ob.instances中的var ckid){if(cke_ob.instances[ckid].focusManager.hasFocus)break;}cke ob.instances[ckid].insertHtml(\'\',\'unfiltered_html\');警报('.$msg');var dialog=cke ob.dialog.getCurrent();dialog.hide();
印刷费($re);
}
else$re='alert(“无法上载文件”);
}
else$re='alert(“.$re.”);
}
@标题('Content-type:text/html;charset=utf-8');
回音“.$re.”;
}
}

当我从本地浏览图像并上传到服务器时,这个函数工作正常,但当我从Word复制图像和方程时,它会上传为图像,但在编辑器中什么也并没有。我在控制台中检查了网络状态,它显示

CKEditorFuncNum是$\u GET['CKEditorFuncNum']中未定义的索引


请检查您使用的CKEditor版本,因为当您使用Ctrl+C/Ctrl+V从Word复制粘贴(而不是拖放)图像时,如果没有上载程序,则应上载图像或将图像转换为base64字符串。此功能是在CKEditor 4.8.0My中引入的,CKEditor版本为4.9.2..images uploads,但上传后会出现在编辑器中。它给出错误“错误的服务器响应”