{"id":78,"date":"2005-11-18T11:35:33","date_gmt":"2005-11-18T11:35:33","guid":{"rendered":"http:\/\/www.plutino.net\/journals\/ethan\/?p=78"},"modified":"2005-11-18T11:52:15","modified_gmt":"2005-11-18T11:52:15","slug":"simple-pleasures","status":"publish","type":"post","link":"https:\/\/www.plutino.net\/journals\/ethan\/?p=78","title":{"rendered":"Simple Pleasures"},"content":{"rendered":"<p>[Warning to the casual reader&#8230;this post is filed under Monkey Brains, <a href=\"http:\/\/www.plutino.net\/journals\/ethan\/?p=67\">with all that that entails<\/a>.]<\/p>\n<p>Today during the course of my <a href=\"http:\/\/www.iedconline.org\/\">work<\/a> I whipped up this quick, easy php function for getting the <a href=\"http:\/\/www.ltsw.se\/knbase\/internet\/mime.htp\">mime-type<\/a> of a file based on the extension of the file name.  I&#8217;m sure there are many different and\/or better ways of doing this, but I thought my way was kind of&#8230;cute.  Also, for the purposes of what I was trying to do, it only made sense to include mime-types that you&#8217;d generally come across when dealing with webpages.<\/p>\n<pre>\r\nfunction getMimeTypeFromExtension($file_name) {\r\n\t$file_extension = preg_replace('\/.*\\.([^$]*)$\/', '$1', $file_name);\r\n\r\n\t$mime_type_array = array(\r\n\t\t'bmp' => 'image\/bmp',\r\n\t\t'doc' => 'application\/msword',\r\n\t\t'gif' => 'image\/gif',\r\n\t\t'htm' => 'text\/html',\r\n\t\t'html' => 'text\/html',\t\t\r\n\t\t'jpg' => 'image\/jpeg',\r\n\t\t'jpeg' => 'image\/jpeg',\r\n\t\t'jpe' => 'image\/jpeg',\r\n\t\t'pdf' => 'application\/pdf',\r\n\t\t'png' => 'image\/png',\r\n\t\t'tif' => 'image\/tiff',\r\n\t\t'tiff' => 'image\/tiff',\r\n\t\t'txt' => 'text\/plain',\r\n\t\t'xls' => 'application\/vnd.ms-excel'\r\n\t);\r\n\t\r\n\t$mime_type = $mime_type_array[$file_extension];\r\n\t\r\n\tif ($mime_type == '') {\r\n\t\t$mime_type = NULL;\r\n\t}\r\n\treturn $mime_type;\r\n}\r\n<\/pre>\n<p>As a personal style note, I always use double-quotes and not single-quotes in code because I think it generally makes the code more portable.  I did a find and replace here because WordPress wants to escape double-quotes inside <code>&lt;pre&gt;<\/code> tags with backslashes.  Keep an eye out for a future post in which I maniacally rant about the uniformity of formatting standards in code.<\/p>\n<p>Also, a week or so ago I wrote a simple javascript form for testing <a href=\"http:\/\/www.regular-expressions.info\/\">regular expression<\/a> replacements.  I put it up <a href=\"http:\/\/www.plutino.net\/dev\/regexreplace.html\">here<\/a> for public consumption.  I love RegEx.  It is really a shame that regular expressions are not supported in <a href=\"http:\/\/www.macromedia.com\/support\/flash\/action_scripts\/actionscript_dictionary\/\">ActionScript<\/a> , although there are a couple decent custom RegEx objects out there:<br \/>\n<a href=\"http:\/\/www.jurjans.lv\/flash\/RegExp.html\">http:\/\/www.jurjans.lv\/flash\/RegExp.html<\/a><br \/>\n<a href=\"http:\/\/homepage.ntlworld.com\/andy_black\/andy\/flash\/regexp\/\">http:\/\/homepage.ntlworld.com\/andy_black\/andy\/flash\/regexp\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Warning to the casual reader&#8230;this post is filed under Monkey Brains, with all that that entails.] Today during the course of my work I whipped up this quick, easy php function for getting the mime-type of a file based on &hellip; <a href=\"https:\/\/www.plutino.net\/journals\/ethan\/?p=78\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-78","post","type-post","status-publish","format-standard","hentry","category-monkey-brains"],"_links":{"self":[{"href":"https:\/\/www.plutino.net\/journals\/ethan\/index.php?rest_route=\/wp\/v2\/posts\/78","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.plutino.net\/journals\/ethan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.plutino.net\/journals\/ethan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.plutino.net\/journals\/ethan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.plutino.net\/journals\/ethan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=78"}],"version-history":[{"count":0,"href":"https:\/\/www.plutino.net\/journals\/ethan\/index.php?rest_route=\/wp\/v2\/posts\/78\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.plutino.net\/journals\/ethan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.plutino.net\/journals\/ethan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=78"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.plutino.net\/journals\/ethan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}