This file contains HTML or script code that may be erroneously interpreted by a web browser

The Error: This file contains HTML or script code that may be erroneously interpreted by a web browser

This is a common error when uploading files that the MediaWiki system does not allow.  By making some minor changes to the MediaWiki LocalSettings.php file, we can fix this.

For demo purposes, I'm going to make our system recognize SWF files (by default these are disallowed):


Add the following line to somewhere in the LocalSettings.php file in the web root folder where your MediaWiki is installed:

$wgFileExtensions[] = 'swf';
  1.  $wgFileExtensions[] = 'swf'

or if you already have an array, just add it to the end:

$wgFileExtensions = array('png', 'gif', 'jpg', 'jpeg', 'doc', 'ppt', 'xls', 'mpp', 'pdf', 'zip', 'flv', 'swf');
  1.  $wgFileExtensions = array('png', 'gif', 'jpg', 'jpeg', 'doc', 'ppt', 'xls', 'mpp', 'pdf', 'zip', 'flv', 'swf')


Online forums are saying this is it, but my system still didn't allow them and returned the above error...


Edit your /includes/specials/SpecialUpload.php file and add the following line shortly after the declaration of detectScript function:

if ($extension === 'swf') return false;
  1.  if ($extension === 'swf') return false

I put it straight after:

function detectScript($file, $mime, $extension) {
	global $wgAllowTitlesInSVG;
  1.  function detectScript($file, $mime, $extension) { 
  2.      global $wgAllowTitlesInSVG
  3.  ... 
That's all I do.  This means that you are allowing all SWF files to be uploaded.  You will be restricted in how big the SWF files are by your server.  We changed ours to 20Mb to accommodate for 5 minute SWF videos...


If the screen just goes blank when you've uploaded a file, then you'll need to debug. Put the following code at the beginning of your LocalSettings.php file:
# for debug purposes
ini_set("display_errors", 1);
$wgShowExceptionDetails = true;
$wgShowSQLErrors = true;
$wgDebugDumpSql  = true;
$wgDebugLogFile  = '/var/www/html/debug_log.txt';
  1.  # for debug purposes 
  2.  error_reporting(E_ALL)
  3.  ini_set("display_errors", 1)
  4.  $wgShowExceptionDetails = true
  5.  $wgShowSQLErrors = true
  6.  $wgDebugDumpSql  = true
  7.  $wgDebugLogFile  = '/var/www/html/debug_log.txt'


I still couldn't upload SWF files despite following all the information on the Internet. Ultimately I fixed this by a worrying fix...: modify /includes/MimeMagic.php under the line 434 "function doGuessMimeType()

function doGuessMimeType( $file, $ext = true ) {
		return "application/x-shockwave-flash";
  1.  function doGuessMimeType( $file, $ext = true ) { 
  2.          return "application/x-shockwave-flash"
Of course this means that any mime types it's not sure about, it will return as shockwave files. This could be a security concern but as our MediaWiki is on our Intranet for Staff use only, it isn't.
Category: Hypertext Markup Language :: Article: 215

Credit where Credit is Due:

Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman

Related Articles

Joes Revolver Map


Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Donate to Joel Lipman via PayPal

Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.