Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify mime type of php file as application/javascript

Tags:

javascript

php

Is it possible to specify the MIME type of a PHP file as application/javascript? I have a PHP file that outputs some JavaScript. When strict MIME type checking is enabled, the browser reports an error:

"Refused to execute script from *.php' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled."

Adding this to the PHP file doesn't help:

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

Here is my code:

<?
  header('Content-Type: application/javascript');
  include ("../admin/config.php");
  include ("../custom_functions.php");
?>
var availableTags = ["BBCD"
<? 
  $prods=decode_prods();
  foreach($prods as $key=>$val){  
?>
, "
<?
  $prods[$key][name] = preg_replace("/(\015\012)|(\015)|(\012)/","",$prods[$key][name]); 
  trim($prods[$key][name]);
  $prods[$key][name]= str_replace("&", "and", $prods[$key][name]);
  $prods[$key][name]= str_replace('"', '', $prods[$key][name]);
  echo $prods[$key][name];
?>
"
<? } ?>
];

I tried adding this to .htaccess after reading this post - but it didn't help.

<Files /js/auto.php>
AddType application/javascript .js
</Files>
like image 948
Pete D Avatar asked Dec 07 '16 11:12

Pete D


People also ask

How do I change the MIME type for a file?

Click Content Settings. Click the MIME tab in the form. Edit the default content-type, content-language, and character set values as necessary. Optional: If necessary, select File extensions are case sensitive to distinguish between uppercase and lowercase letters when comparing file extensions.

How can I get MIME type from uploaded file in PHP?

PHP | mime_content_type() function. The mime_content_type() function is an inbuilt function in PHP which is used to get the MIME content-type of a file. Parameters: This function accepts single parameter $file which specifies the path of the file which MIME details to be find.

What is MIME type in Javascript?

MIME (Multipurpose Internet Mail Extensions) type is a standard way of describing a data type in the body of an HTTP message or email. The MIME type is passed in the Content-Type header. For example, the Content-Type: text/html header tells the browser that it received an HTML page.


1 Answers

you mean something like that?

header('Content-Type: application/javascript');
like image 117
Tom St Avatar answered Oct 05 '22 09:10

Tom St