82952

Including php file as JS

Question:

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:

<a href="http://tinymce.moxiecode.com/wiki.php/Configuration%3aexternal_image_list_url" rel="nofollow">http://tinymce.moxiecode.com/wiki.php/Configuration%3aexternal_image_list_url</a>

Answer1:

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 <a href="http://tinymce.moxiecode.com/wiki.php/Configuration%3aexternal_image_list_url" rel="nofollow">TinyMCE docs</a>, please make sure that there is no whitespace before the <?php opening tag in the dynamically generated JS, also check for <a href="http://en.wikipedia.org/wiki/Byte_order_mark" rel="nofollow">UTF8 BOM</a> which can be a sneaky cause of invisible output.

Answer2:

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

Answer3:

This is definitely a problem of incorrect header type.

could you please change the line

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

to

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

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

Recommend

  • Skype messages are pending in queue when sent from java
  • How to initialize widget in component Vue?
  • Outlook 365 add-in only appears in Outlook 2013 client
  • Why are Google search results in UIWebView not triggering webViewDidFinishLoad?
  • Remove 2 vertical borders from HTML table - how?
  • How do I extract xml properties using shell scripts?
  • Andengine loading graphics: why is my background texture small and upside down
  • How to make image control button for each image inside the div using css and js?
  • D3 Tree layout visualization - Inherit child with multiple parents
  • Directory structure and labeling in Caffe
  • Convert base64 image to a file in Node Js
  • Python Pillow: Make gradient for transparency
  • Problems using HOGDescriptor
  • Different SSL-certificates for different parts of site
  • How can I stop .htaccess redirecting a subdomain to the main site?
  • Httpclient multipart/form-data post image and json same time
  • BackgroundMediaPlayer set Uri source of Media library item
  • ResponseBuilder is not working when used with entity object
  • Is it possible to control programs with Javascript?
  • Intent Image Capture data==null
  • C# Remove URL from String
  • PHP Copy function not working
  • How to set download location via chrome api
  • PHP file_exists() anomaly
  • MVVM: Image Bind Source from FileOpenPicker
  • azure media services - The request body is too large and exceeds the maximum permissible limit
  • Syntax for setting draggablecursor property in google maps api
  • Resize panoramic image to fixed size
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Circular dependency while pushing http interceptor
  • AngularJs get employee from factory
  • Benchmarking RAM performance - UWP and C#
  • How to set the response of a form post action to a iframe source?
  • Angular 2 constructor injection vs direct access
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Change div Background jquery
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • How can I remove ASP.NET Designer.cs files?
  • java string with new operator and a literal