2017-10-11 68 views
0

我有一個關於nicEditor for textarea的問題。NicEdit上傳圖片但在編輯器中顯示空白圖片

當我從本地存儲器上傳圖像到niceeditor上傳到文件夾和數據庫,但doesen't不顯示在textarea。 enter image description here

正如你可以在圖像文本編輯器中看到顯示空白圖像。我的代碼如下: 。

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); 
} 
?> 

圖像將成功上傳到文件夾和數據庫。

+1

檢查您的控制檯或檢查img,看看它返回什麼? –

回答

0

發現以下Sollution

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); 
} 
?> 

DONE!現在我嘗試上傳東西,它會直接到您的服務器

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