I'm using Froalo for text editing, but I'm having difficulties getting the image upload to function correctly. Testing on localhost.
The documentation says that
imageUploadURL: '/upload_image.php',
should return a json string formated like this :
{ link: 'path/to/image.jpg' }
my javascript looks this this :
$(function() {
$('#edit').froalaEditor({
language:'fr',
imageUploadURL: 'upload.php'
})
});
my upload.php looks like this :
var_dump($_FILES);
require('clean.php'); // removes french special characters
$image = clean($_FILES['file']['name']);
$uploaddir = '../photos/';
$uploadfile = $uploaddir . basename($image);
$retour = ['link'=> $uploadfile];
$b = json_encode($retour);
$array_final = preg_replace('/"([a-zA-Z]+[a-zA-Z0-9_]*)":/','$1:',$b);
if( move_uploaded_file($_FILES['file']['tmp_name'],$uploadfile)) {
echo stripslashes($array_final);
} else {
echo "Lo kol kakh tov...";
}
When I run this from the text editor through froalaEditor,
- the file gets uploaded to the server,
firebug says that upload.php answers the array $_FILES and :
{link:"../photos/sama1.jpg"}
That all seems good, but froala answers that "something" went wrong and the images doesn't appear in the editor.
Could it be because of the double quotes around the image url?
json_encode()
can automatically take care of that. – Muntashir Akon