1

I am trying to change the image_list_url of tiny_mce to php file.

I changed the url to image_list.php file. It generated the exact output text same as the js file.

But even after giving same output it doesn't show's the image list.

I am wondering if the content-type is affecting it or not?

my JS file content:

// This list may be created by a server logic page PHP/ASP/ASPX/JSP in some backend system.
// There images will be displayed as a dropdown in all image dialogs if the "external_link_image_url"
// option is defined in TinyMCE init.

var tinyMCEImageList = new Array(
    // Name, URL
    ["Logo 1", "media/logo.jpg"],
    ["Logo 2 Over", "media/logo_over.jpg"]
);

my PHP COde:

<?php
    require('../../../system/config.php');
    $strPath = APP_ROOT.DS.'sys_uploads/images/';
    $objFileList = dir( $strPath );
    $arrFileList = array();
    while (false !== ($entry = $objFileList->read())) {
        if( is_file( $strPath.$entry) )
            $arrFileList[] = array($entry, ABS_URL.'/sys_uploads/images/'.$entry);
    }
    $objFileList->close();

    header('Content-type: application/x-javascript');
    //header('Content-type: text');
?>
// This list may be created by a server logic page PHP/ASP/ASPX/JSP in some backend system.
// There images will be displayed as a dropdown in all image dialogs if the "external_link_image_url"
// option is defined in TinyMCE init.

var tinyMCEImageList = new Array(
    // Name, URL
 <?php
    if( count( $arrFileList )>0 )
        foreach( $arrFileList as $dataRow ):
 ?>
    ["<?php echo $dataRow[0];?>", "<?php echo $dataRow[1];?>"],
 <?php endforeach; ?>
);

my PHP Output:

// This list may be created by a server logic page PHP/ASP/ASPX/JSP in some backend system.
// There images will be displayed as a dropdown in all image dialogs if the "external_link_image_url"
// option is defined in TinyMCE init.

alert('test working or not');

var tinyMCEImageList = new Array(
    // Name, URL
    ["Logo 1", "media/logo.jpg"],
    ["Logo 2 Over", "media/logo_over.jpg"]
);

Edit:

As per suggestion i even added a popup message too which even didn't show up.

Solution:

dun know what was error on my code but found good solution from link suggested:

http://tinymce.moxiecode.com/wiki.php/Configuration%3aexternal_image_list_url

2
  • Why do you count the size of $arrFileList? That's not required for foreach as long as it's an array. Commented Apr 5, 2011 at 8:10
  • i want to skip if its blank... thnx for suggestion... it helps me optimising my code Commented Apr 5, 2011 at 8:13

3 Answers 3

1

As both the .js and your PHP file outputs are identical, there should be no difference. text/javascript is the most widely supported mime type for JS, so using that might help.

It would also not hurt to name your dynamically generated JS files using a convention such as XYZ.php.js and using mod_rewrite to parse the php.js files as php.

Edit:

Also, per official TinyMCE docs, please make sure that there is no whitespace before the <?php opening tag in the dynamically generated JS, also check for UTF8 BOM which can be a sneaky cause of invisible output.

Sign up to request clarification or add additional context in comments.

6 Comments

i tried adding header('Content-type: text/javascript'); too but it didn't helped... well abt second idea that's also great ... i will be trying it
How are you including the js file?
its just from tiny_mce script... ie. specifying it in options of tiny_mce_url list...
Could very well be the cause. Try doing what I suggested in second part of my answer and see if it helps.
about white space m pretty sure there isn't any. but how do i check UTF8 BOM
|
0

No need to change any headers. Just output the JavaScript.

js.php: alert("Working!")

test.htm: <script type="text/javascript" src="js.php"></script>

When I loaded test.htm, I got an alert box

Comments

0

This is definitely a problem of incorrect header type.

could you please change the line

header('Content-type: application/x-javascript');

to

header('Content-type: application/javascript');

As application/x-javascript is not a correct javascript header. Tell me if this thing helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.