NicEdit: uploading image to own server does not work & # 8594; wrong configuration?

I have a problem with nicEditor for text fields, to be more precise; image upload button.

My index.php file contains the name where nicEditor is called. In the same folder are two other folders: โ€œimagesโ€, where I want to store files and โ€œincludesโ€, where nicEdit.js and nicUpload.php (which contains the download code provided from the official site).

My problem: when I want to upload an image via nicEdit, I get the error message "Failed to upload image" appears, although I set the following options:

  • In nicEdit.js, nicURI is set to "includes / nicUpload.php"
  • In nicUpload.php, NICUPLOAD_PATH is defined as "./images", and NICUPLOAD_URI is defined as "images" (I tried several other combinations here, but nobody works)
  • The "images" folder has a resolution of 777

I spent hours just trying and making a mistake, but I could not achieve any positive results ...

[edit]:

When I upload a larger file, I see that the download process is loading, but as soon as it is completed, the message "Could not load image"

The code in nicEdit.js includes:

var nicUploadButton=nicEditorAdvancedButton.extend({nicURI:'includes/nicUpload.php',errorText:"Failed to upload image",addPane:function ...... 
+4
source share
4 answers

The solution is Simple !!!

1 - CREATE image.php FILE and paste the code:

 <?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("upload" => array( "links" => array("original" => $link), "image" => array("width" => $data[0], "height" => $data[1] ) )); //echo out the response :) echo json_encode($res); } ?> 

2 - Open and edit the nickedit.js file:

 Find the line starting like nicURI:"http://api.imgur.com/2/upload.json" Replace it with nicURI:"image.php" DONE ! Now try uploading something and it would go directly to your server :) 

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

+6
source

NicEdit developers did something bad .

They updated the version of nicUpload.js for imgur.com , which is incompatible with nicUpload.php . When you download lib from your page, the server simply includes the imgur version in nicEdit.js .

I will figure out how to do it.

Checkout their svn repository on version 23

  svn checkout http://svn.nicedit.com//trunk/nicUpload/ svn update -r 23 

Edit the uncompressed version of the code nicEdit.js , delete between

 /* START CONFIG */ var nicUploadOptions = { buttons : { 'upload' : {name : 'Upload Image', type : 'nicUploadButton'} } 

and

 nicEditors.registerPlugin(nicPlugin,nicUploadOptions); 

Paste nicUpload.js from nicUpload/ from svn.

And delete this line:

 /* NICEDIT_REMOVE_START */,iconFiles : {'upload' : 'src/nicUpload/icons/upload.gif'}/* NICEDIT_REMOVE_END */ 
+3
source

A simple solution still works with version 25 (compressed). The res array should replace as mentioned above. Make sure the syntax is correct.
There is also a file size limit - actually 2M. Try changing it in code or file. And do not forget to first create a download folder and add the correct link.
Hope this helps someone. Keep calm.

0
source

If you are booting from the htaccess protected zone, you need to delete

 C.setRequestHeader("Authorization","Client-ID c37fc05199a05b7"); 

... in var nicUploadButton to avoid prompting without accepting your input values. It seems to be working now.

0
source

Source: https://habr.com/ru/post/1437464/


All Articles