Forum breadcrumbs – You are here:Asgaros Support ForumSupportAdd servimg access
Please or Register to create posts and topics.

Add servimg access

PreviousPage 2 of 2

i just add TinyMCE config plugin, with this you can add some params to the TinyMCE standard module from WordPress

i have install this 2 plugins :

  • Advanced TinyMCE Configuration
  • TinyMCE Advanced

I add some options to tiny :

  • images_upload_url : true
  • images_upload_base_path : /uploads

I found some informations here :

https://www.tiny.cloud/docs/general-configuration-guide/upload-images/

I think with TinyMCE upload function is ready, but for while i cant configure it

Uploaded files:
  • Capture-d’écran-2018-12-17-à-13.36.49.png

It seems that an additional PHP upload-helper is necessary for this which process (uploads) the files:

https://www.tiny.cloud/docs/advanced/php-upload-handler/

Not sure if something like this is already implemented in WordPress. I would suggest to check the WordPress plugin-repository. Maybe there is already a TinyMCE-extensions which adds an out-of-the-box-working upload-functionality to the editor connected to WordPress.

franky has reacted to this post.
franky
If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Done !!

i can now upload image to my server directly in a post message

I use the Advanced TinyMCE Configuration plugin

Add option name in it :

  • images_upload_base_path : <my upload folder>
  • images_upload_url : <my upload folder><my page php>
  • images_upload_handler :
    function (blobInfo, success, failure) {
    var xhr, formData;

    xhr = new XMLHttpRequest();
    xhr.withCredentials = false;
    xhr.open(‘POST’, ‘<my upload folder><my page php>‘);

    xhr.onload = function() {
    var json;
    console.log(“RETURN XHR”);
    console.log(xhr);

    if (xhr.status != 200) {
    failure(‘HTTP Error ::: ‘ + xhr.status + xhr.statusText);
    return;
    }

    json = JSON.parse(xhr.responseText);

    if (!json || typeof json.location != ‘string’) {
    failure(‘Invalid JSON: ‘ + xhr.responseText);
    return;
    }

    success(json.location);
    };

    formData = new FormData();
    formData.append(‘file’, blobInfo.blob(), blobInfo.filename());

    xhr.send(formData);
    }

 

And a php page like this :

<?php
function toIsoString($text) {
$string = iconv (‘UTF-8’, ‘US-ASCII//TRANSLIT//IGNORE’, $text);
$string = preg_replace (‘#[^.0-9a-z]+#i’, ”, $string);
$string = strtolower ($string);
return $string;
}

/*******************************************************
* Only these origins will be allowed to upload images *
******************************************************/
$accepted_origins = array(“<your http web site>”);

/*********************************************
* Change this line to set the upload folder *
*********************************************/
$imageFolder = “<your folder>”;

reset ($_FILES);
$temp = current($_FILES);
if (is_uploaded_file($temp[‘tmp_name’])){
if (isset($_SERVER[‘HTTP_ORIGIN’])) {
// same-origin requests won’t set an origin. If the origin is set, it must be valid.
if (in_array($_SERVER[‘HTTP_ORIGIN’], $accepted_origins)) {
header(‘Access-Control-Allow-Origin: ‘ . $_SERVER[‘HTTP_ORIGIN’]);
} else {
header(“HTTP/1.1 403”);
return;
}
}

/*
If your script needs to receive cookies, set images_upload_credentials : true in
the configuration and enable the following two headers.
*/
// header(‘Access-Control-Allow-Credentials: true’);
// header(‘P3P: CP=”There is no P3P policy.”‘);

// Sanitize input

$isoName = toIsoString($temp[‘name’]);

if (preg_match(“/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/”, $isoName)) {
header(“HTTP/1.1 400 file bad name : “.$isoName);
return;
}

// Verify extension
if (!in_array(strtolower(pathinfo($isoName, PATHINFO_EXTENSION)), array(“gif”, “jpg”, “png”))) {
header(“HTTP/1.1 400 bad file format.”);
return;
}

// Accept upload if there was no origin, or if it is an accepted origin
$filetowrite = time() . “_” . $isoName;
move_uploaded_file($temp[‘tmp_name’], $filetowrite);

// Respond to the successful upload with JSON.
// Use a location key to specify the path to the saved image resource.
// { location : ‘/your/uploaded/image/file’}
echo json_encode(array(‘location’ => $imageFolder . $filetowrite));
} else {
// Notify editor that the upload failed
header(“HTTP/1.1 500 server error”);
}

?>

Asgaros has reacted to this post.
Asgaros

Nice job. I am glad to hear that you found a solution! 🙂

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

thx, i hope this soluce can be integrate in a future version

PreviousPage 2 of 2