Add servimg access
Quote from franky on December 17, 2018, 1:19 pmi just add TinyMCE config plugin, with this you can add some params to the TinyMCE standard module from WordPress
i just add TinyMCE config plugin, with this you can add some params to the TinyMCE standard module from WordPress
Quote from franky on December 17, 2018, 1:32 pmi 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
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:Quote from Asgaros on December 17, 2018, 1:40 pmIt 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.
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.
Quote from franky on December 18, 2018, 3:25 pmDone !!
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”);
}?>
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”);
}?>
Quote from Asgaros on December 18, 2018, 8:42 pmNice job. I am glad to hear that you found a solution! 🙂
Nice job. I am glad to hear that you found a solution! 🙂