EdmondCaputo/getMIMEtype functions PHP and Javascript

Using the freedesktop.org.xml file as a starting point, I wrote a simple PHP program to generate two "getMIMEtype()" functions, one for PHP and the other for Javascript. The intent is to make it easy to update the mime-type functions when new types are added.

Generated PHP getMIMEtype function: getMIMEtype.php

Generated Javascript getMIMEtype function: getMIMEtype.js

MakeGetMIMEtype.php: (MakeGetMIMEtype.php)

<?php // make getMIMEtype() functions for PHP and JS, starting from freedesktop.org.xml

// create document header echo ' <html>

';

$xmlFilename = "freedesktop.org.xml"; // input file $phpFilename = "getMIMEtype.php"; // output file $jsFilename = "getMIMEtype.js"; // output file

$xml = simplexml_load_file($xmlFilename) or die ("XML error: Unable to load XML file ".$xmlFilename."!"); //print_r($xml); // php file $phpHandle = fopen($phpFilename, "wb"); fwrite($phpHandle, '<?PHP function getMIMEtype($filename) {

' ); // javascript file $jsHandle = fopen($jsFilename, "wb"); fwrite($jsHandle, ' function getMIMEtype(filename) {

' ); foreach ($xml->{'mime-type'} as $mimetype) {

');

');

');

');

} // php file fwrite($phpHandle, ' return("binary/octet-stream"); } ?>'); fclose($phpHandle); chmod($phpFilename, 0666); // javascript file fwrite($jsHandle, ' return("binary/octet-stream"); }'); fclose($jsHandle); chmod($jsFilename, 0666);

echo $phpFilename . ' CREATED<BR/>'; echo $jsFilename . ' CREATED<BR/>';

// create document footer echo '

</html> '; ?>

END - MakeGetMIMEtype.php