将图像粘贴到CKEditor后修改html

时间:2017-03-31 02:25:39

标签: javascript jquery ckeditor

当我将图像粘贴到CKEditor中时,图像会上传到服务器并显示在CKEditor中。如何在已经上传的情况下修改html并在CKEditor上显示图像。当我粘贴图像时,html源代码就像这样

<p><img src="upload/images/tes.png  " style="height:768px; width:1366px" /></p>

我如何修改为这样

<div class="imagebox">
   <p><img src="upload/images/tes.png" class="mylightbox" style="height:300px; width:600px" /></p>
</div>

我的CKEditor设置

<script>
var editor = CKEDITOR.replace('editor1', {
    filebrowserBrowseUrl: "browse.php",
    filebrowserUploadUrl: "upload.php?responseType=json"
});

editor.on('fileUploadResponse', function(evt) {
    // Prevent the default response handler.
    evt.stop();

    // Get XHR and response.
    var data = evt.data,
        xhr = data.fileLoader.xhr,
        response = xhr.responseText.split('|');

    if (response[1]) {
        // An error occurred during upload.
        data.message = response[1];
        evt.cancel();
    } else {
        data.url = response[0];
    }
});
</script>

和我的upload.php代码

<?php
if(isset($_GET['CKEditorFuncNum'])){
// Required: anonymous function reference number as explained above.
$funcNum = $_GET['CKEditorFuncNum'] ;
// Optional: instance name (might be used to load a specific configuration 
file or anything else).
$CKEditor = $_GET['CKEditor'] ;
// Optional: might be used to provide localized messages.
$langCode = $_GET['langCode'] ;
// Optional: compare it with the value of `ckCsrfToken` sent in a cookie to 
protect your server side uploader against CSRF.
// Available since CKEditor 4.5.6.
$token = $_POST['ckCsrfToken'] ;
// Check the $_FILES array and save the file. Assign the correct path to a 
variable ($url).
$url = 'tes.png';
// Usually you will only assign something here if the file could not be 
uploaded.
$message = 'The uploaded file has been renamed';
echo "<script 
type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, 
'$url', '$message');</script>";     
 }else{
$filename = "tes.png";
$destination_path = getcwd().DIRECTORY_SEPARATOR;
$target_path = $destination_path . "/upload/images/" . $filename;
if(move_uploaded_file($_FILES["upload"]["tmp_name"], $target_path)){
    echo "upload/images/".$filename;
}   
}
?>

请有人可以帮我吗? 感谢

0 个答案:

没有答案