TinyMCE Absolute URL contains script file name
up vote
0
down vote
favorite
I am having an issue getting the correct absolute URL when uploading a file in TinyMCE.
When I upload a file, the URL shown in the Source field contains the file name of the page that the code is called from: (create_email.php)
Like this:
https://mydomain/admin/email_send/create_email.phpimages/62b39_nophoto.jpg
Instead of:
https://mydomain/admin/email_send/images/62b39_nophoto.jpg
The image does upload correctly and the stored file name is correct. Just the passed URL is incorrect.
TinyMCE Init Code:
tinymce.init({
selector: 'textarea',
height: 200,
menubar: true,
relative_urls : false,
remove_script_host : false,
document_base_url : "https://mydomain/admin/email_send/images/",
images_upload_handler: function (blobInfo, success, failure) {
var xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', 'uploader2.php');
xhr.onload = function() {
var json;
if (xhr.status != 200) {
failure('HTTP Error: ' + xhr.status);
return;
}
console.log(xhr.response);
success(xhr.response);
};
formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
xhr.send(formData);
},
Uploader Code:
<?php
$ds = DIRECTORY_SEPARATOR;
$storeFolder = 'images';
if (!empty($_FILES))
{
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$file_name = substr(md5(rand(1, 213213212)), 1, 5) . "_" . str_replace(array(''', '"', ' ', '`'), '_', $_FILES['file']['name']);
$targetFile = $targetPath. $file_name;
if(move_uploaded_file($tempFile,$targetFile)){
die( $_SERVER['HTTP_REFERER']. $storeFolder . "/" . $file_name );
}else{
die('Fail');
}
}
?>
plugins: [
'advlist autolink lists link image imagetools charmap print preview
anchor textcolor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table contextmenu paste code help wordcount'
],
toolbar: 'insert | undo redo | formatselect | bold italic backcolor |
alignleft aligncenter alignright alignjustify | bullist numlist outdent
indent | removeformat | help',
content_css: [
'//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
'//www.tinymce.com/css/codepen.min.css']
});
php tinymce
add a comment |
up vote
0
down vote
favorite
I am having an issue getting the correct absolute URL when uploading a file in TinyMCE.
When I upload a file, the URL shown in the Source field contains the file name of the page that the code is called from: (create_email.php)
Like this:
https://mydomain/admin/email_send/create_email.phpimages/62b39_nophoto.jpg
Instead of:
https://mydomain/admin/email_send/images/62b39_nophoto.jpg
The image does upload correctly and the stored file name is correct. Just the passed URL is incorrect.
TinyMCE Init Code:
tinymce.init({
selector: 'textarea',
height: 200,
menubar: true,
relative_urls : false,
remove_script_host : false,
document_base_url : "https://mydomain/admin/email_send/images/",
images_upload_handler: function (blobInfo, success, failure) {
var xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', 'uploader2.php');
xhr.onload = function() {
var json;
if (xhr.status != 200) {
failure('HTTP Error: ' + xhr.status);
return;
}
console.log(xhr.response);
success(xhr.response);
};
formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
xhr.send(formData);
},
Uploader Code:
<?php
$ds = DIRECTORY_SEPARATOR;
$storeFolder = 'images';
if (!empty($_FILES))
{
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$file_name = substr(md5(rand(1, 213213212)), 1, 5) . "_" . str_replace(array(''', '"', ' ', '`'), '_', $_FILES['file']['name']);
$targetFile = $targetPath. $file_name;
if(move_uploaded_file($tempFile,$targetFile)){
die( $_SERVER['HTTP_REFERER']. $storeFolder . "/" . $file_name );
}else{
die('Fail');
}
}
?>
plugins: [
'advlist autolink lists link image imagetools charmap print preview
anchor textcolor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table contextmenu paste code help wordcount'
],
toolbar: 'insert | undo redo | formatselect | bold italic backcolor |
alignleft aligncenter alignright alignjustify | bullist numlist outdent
indent | removeformat | help',
content_css: [
'//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
'//www.tinymce.com/css/codepen.min.css']
});
php tinymce
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am having an issue getting the correct absolute URL when uploading a file in TinyMCE.
When I upload a file, the URL shown in the Source field contains the file name of the page that the code is called from: (create_email.php)
Like this:
https://mydomain/admin/email_send/create_email.phpimages/62b39_nophoto.jpg
Instead of:
https://mydomain/admin/email_send/images/62b39_nophoto.jpg
The image does upload correctly and the stored file name is correct. Just the passed URL is incorrect.
TinyMCE Init Code:
tinymce.init({
selector: 'textarea',
height: 200,
menubar: true,
relative_urls : false,
remove_script_host : false,
document_base_url : "https://mydomain/admin/email_send/images/",
images_upload_handler: function (blobInfo, success, failure) {
var xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', 'uploader2.php');
xhr.onload = function() {
var json;
if (xhr.status != 200) {
failure('HTTP Error: ' + xhr.status);
return;
}
console.log(xhr.response);
success(xhr.response);
};
formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
xhr.send(formData);
},
Uploader Code:
<?php
$ds = DIRECTORY_SEPARATOR;
$storeFolder = 'images';
if (!empty($_FILES))
{
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$file_name = substr(md5(rand(1, 213213212)), 1, 5) . "_" . str_replace(array(''', '"', ' ', '`'), '_', $_FILES['file']['name']);
$targetFile = $targetPath. $file_name;
if(move_uploaded_file($tempFile,$targetFile)){
die( $_SERVER['HTTP_REFERER']. $storeFolder . "/" . $file_name );
}else{
die('Fail');
}
}
?>
plugins: [
'advlist autolink lists link image imagetools charmap print preview
anchor textcolor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table contextmenu paste code help wordcount'
],
toolbar: 'insert | undo redo | formatselect | bold italic backcolor |
alignleft aligncenter alignright alignjustify | bullist numlist outdent
indent | removeformat | help',
content_css: [
'//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
'//www.tinymce.com/css/codepen.min.css']
});
php tinymce
I am having an issue getting the correct absolute URL when uploading a file in TinyMCE.
When I upload a file, the URL shown in the Source field contains the file name of the page that the code is called from: (create_email.php)
Like this:
https://mydomain/admin/email_send/create_email.phpimages/62b39_nophoto.jpg
Instead of:
https://mydomain/admin/email_send/images/62b39_nophoto.jpg
The image does upload correctly and the stored file name is correct. Just the passed URL is incorrect.
TinyMCE Init Code:
tinymce.init({
selector: 'textarea',
height: 200,
menubar: true,
relative_urls : false,
remove_script_host : false,
document_base_url : "https://mydomain/admin/email_send/images/",
images_upload_handler: function (blobInfo, success, failure) {
var xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', 'uploader2.php');
xhr.onload = function() {
var json;
if (xhr.status != 200) {
failure('HTTP Error: ' + xhr.status);
return;
}
console.log(xhr.response);
success(xhr.response);
};
formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
xhr.send(formData);
},
Uploader Code:
<?php
$ds = DIRECTORY_SEPARATOR;
$storeFolder = 'images';
if (!empty($_FILES))
{
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$file_name = substr(md5(rand(1, 213213212)), 1, 5) . "_" . str_replace(array(''', '"', ' ', '`'), '_', $_FILES['file']['name']);
$targetFile = $targetPath. $file_name;
if(move_uploaded_file($tempFile,$targetFile)){
die( $_SERVER['HTTP_REFERER']. $storeFolder . "/" . $file_name );
}else{
die('Fail');
}
}
?>
plugins: [
'advlist autolink lists link image imagetools charmap print preview
anchor textcolor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table contextmenu paste code help wordcount'
],
toolbar: 'insert | undo redo | formatselect | bold italic backcolor |
alignleft aligncenter alignright alignjustify | bullist numlist outdent
indent | removeformat | help',
content_css: [
'//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
'//www.tinymce.com/css/codepen.min.css']
});
php tinymce
php tinymce
asked Nov 21 at 12:31
user2413654
10912
10912
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Fixed the issue.
Replaced: die( $_SERVER['HTTP_REFERER']. $storeFolder . "/" . $file_name );
With: die("http://mydomain/admin/email_send/" . $storeFolder . "/" . $file_name );
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Fixed the issue.
Replaced: die( $_SERVER['HTTP_REFERER']. $storeFolder . "/" . $file_name );
With: die("http://mydomain/admin/email_send/" . $storeFolder . "/" . $file_name );
add a comment |
up vote
0
down vote
Fixed the issue.
Replaced: die( $_SERVER['HTTP_REFERER']. $storeFolder . "/" . $file_name );
With: die("http://mydomain/admin/email_send/" . $storeFolder . "/" . $file_name );
add a comment |
up vote
0
down vote
up vote
0
down vote
Fixed the issue.
Replaced: die( $_SERVER['HTTP_REFERER']. $storeFolder . "/" . $file_name );
With: die("http://mydomain/admin/email_send/" . $storeFolder . "/" . $file_name );
Fixed the issue.
Replaced: die( $_SERVER['HTTP_REFERER']. $storeFolder . "/" . $file_name );
With: die("http://mydomain/admin/email_send/" . $storeFolder . "/" . $file_name );
answered Nov 21 at 14:24
user2413654
10912
10912
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412112%2ftinymce-absolute-url-contains-script-file-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown