Since TinyMCE 4.x, TinyMCE has an build in image upload, but I can't get it to work.
My code:
tinymce.init({
selector: "textarea",
plugins: [
"image","code","autoresize","media","link","imagetools"
],
link_class_list: [
{title: 'None', value: ''},
{title: 'PDF', value: 'pdf'}
],
default_link_target: "_blank",
images_upload_url: "uploadImage.php",
toolbar1: "insertfile undo | redo | styleselect | bold | italic | alignleft | aligncenter | alignright | alignjustify | bullist | numlist | outdent | indent | link | image | media | code",
toolbar2: "",
menubar : false,
statusbar : false,
convert_urls: false,
content_css: 'editor-style.css',
width: 800
});
The line: "images_upload_url" shoud be responsible for the image upload. The php file attached to this is the following:
$imageFolder = "../images/tinymce";
reset ($_FILES);
$temp = current($_FILES);
if (is_uploaded_file($temp['tmp_name'])){
if (isset($_SERVER['HTTP_ORIGIN'])) {
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
}
if (preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $temp['name'])) {
header("HTTP/1.0 500 Invalid file name.");
return;
}
if (!in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), array("gif", "jpg", "png"))) {
header("HTTP/1.0 500 Invalid extension.");
return;
}
$filetowrite = $imageFolder . $temp['name'];
move_uploaded_file($temp['tmp_name'], $filetowrite);
echo json_encode(array('location' => $filetowrite));
} else {
header("HTTP/1.0 500 Server Error");
}
Am I missing something? Where can I find the "upload image" button in the editor (I expect it to appear in the "Insert/edit image" window). Is there a working example somewhere?