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



enter image description here



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']
});









share|improve this question


























    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



    enter image description here



    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']
    });









    share|improve this question
























      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



      enter image description here



      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']
      });









      share|improve this question













      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



      enter image description here



      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 at 12:31









      user2413654

      10912




      10912
























          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 );






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            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

























            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 );






            share|improve this answer

























              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 );






              share|improve this answer























                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 );






                share|improve this answer












                Fixed the issue.



                Replaced: die( $_SERVER['HTTP_REFERER']. $storeFolder . "/" . $file_name );



                With: die("http://mydomain/admin/email_send/" . $storeFolder . "/" . $file_name );







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 at 14:24









                user2413654

                10912




                10912






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)