I have a problem regarding the nicEditor for textareas, to be more precise; the picture upload button.
My file index.php contains the where the nicEditor is called. In the same folder are two other folders: "images", where I want to store the files in and "includes", where nicEdit.js and nicUpload.php (which contains the Upload Code provided from the official site) are.
My problem is: When I want to upload a picture via nicEdit, the error message "Failed to upload image." appears, although I have set the follwoing parameters:
I wasted hours just doing try and error but I wasn't able to get any positive results doing so...
[edit]:
When I upload a bigger file, I can see the upload bar progessing, but as soon as it is complete, the "Failed to upload image" appears
the code in nicEdit.js includes:
var nicUploadButton=nicEditorAdvancedButton.extend({nicURI:'includes/nicUpload.php',errorText:"Failed to upload image",addPane:function ......
Solution Simple!!!
1 - CREATE FILE image.php and paste 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 nickedit.js:
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