NicEdit 图片已上传但在编辑器中显示空白图片

NicEdit Picture uploaded but shows blank image in editor

我对 textarea 的 nicEditor 有疑问。

当我从本地存储在 niceeditor 中上传图像时,图像将被上传到文件夹和数据库,但不会显示在文本区域中。

正如您在图片中看到的,文本编辑器显示空白图片。 我的代码如下。

  var nicUploadOptions = {
        buttons : {
            'upload' : {name : 'Upload Image', type : 'nicUploadButton'}
        }

    };
    var nicUploadButton=nicEditorAdvancedButton.extend({nicURI:"image.php" and more..
    nicEditors.registerPlugin(nicPlugin,nicUploadOptions);

而PHP代码如下

<?php
//Check if we are getting the image
if(isset($_FILES['image'])){
        //Get the image array of details
        $img = $_FILES['image'];       
        //The new path of the uploaded image, rand is just used for the sake of it
        $path = "upload/" . rand().$img["name"];
        //Move the file to our new path
        move_uploaded_file($img['tmp_name'],$path);
        //Get image info, reuiqred to biuld the JSON object
        $data = getimagesize($path);
        //The direct link to the uploaded image, this might varyu depending on your script location    
        $link = "http://$_SERVER[HTTP_HOST]"."/nicedit/".$path;
        //Here we are constructing the JSON Object
        $res = array("data" => array( "link" => $link, "width" => $data[0], "height" => $data[1]));
        //echo out the response :)
        echo json_encode($res);
}
?>

图片将成功上传到文件夹和数据库。

找到以下解决方案

 line starting with nicURI:"http://api.imgur.com/2/upload.json" 
    Replace with

    nicURI:"image.php"

而PHP代码是

<?php
//Check if we are getting the image
if(isset($_FILES['image'])){
        //Get the image array of details
        $img = $_FILES['image'];       
        //The new path of the uploaded image, rand is just used for the sake of it
        $path = "upload/" . rand().$img["name"];
        //Move the file to our new path
        move_uploaded_file($img['tmp_name'],$path);
        //Get image info, reuiqred to biuld the JSON object
        $data = getimagesize($path);
        //The direct link to the uploaded image, this might varyu depending on your script location    
        $link = "http://$_SERVER[HTTP_HOST]"."/nicedit/".$path;
        //Here we are constructing the JSON Object
         $res = array("data" => array( "link" => $link, "width" => $data[0], "height" => $data[1]));                          
                    ));
        //echo out the response :)
        echo json_encode($res);
}
?>

完成!现在我尝试上传一些东西,它会直接到你的服务器

我参考 http://manzzup.blogspot.com.br/2014/03/customize-nicedit-image-upload-to.html .