-
-
Save ivanionut/ba9f47404e23dde680ea to your computer and use it in GitHub Desktop.
Update to ColdFusion getMimeType UDF. Update struct creation & add/update mime types. Make filename optional. Passes "application/unknown" if type not found.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* ORIGINAL: http://www.cflib.org/udf/getMimeType | |
| Returns mime type and subtype for a file. | |
| @param filename File name to examine. (optional) | |
| @return Returns a string. | |
| @author Kenneth Rainey (kip.rainey@incapital.com) | |
| @version 1, April 21, 2004 | |
| @version 2, September 1, 2015 https://gist.github.com/JamoCA/5a2cece7e2a248f71ad9 */ | |
| function getMimeType() { | |
| var fileExtension = ""; | |
| var mimeStruct = {"323" = "text/h323", | |
| "7z" = "application/x-7z-compressed", | |
| "aaf" = "application/octet-stream", | |
| "aca" = "application/octet-stream", | |
| "accdb" = "application/msaccess", | |
| "accde" = "application/msaccess", | |
| "accdt" = "application/msaccess", | |
| "acx" = "application/internet-property-stream", | |
| "afm" = "application/octet-stream", | |
| "ai" = "application/postscript", | |
| "aif" = "audio/x-aiff", | |
| "aifc" = "audio/aiff", | |
| "aiff" = "audio/aiff", | |
| "air" = "application/vnd.adobe.air-application-installer-package+zip", | |
| "application" = "application/x-ms-application", | |
| "art" = "image/x-jg", | |
| "asc" = "text/plain", | |
| "asd" = "application/octet-stream", | |
| "asf" = "video/x-ms-asf", | |
| "asi" = "application/octet-stream", | |
| "asm" = "text/plain", | |
| "asr" = "video/x-ms-asf", | |
| "asx" = "video/x-ms-asf", | |
| "atom" = "application/atom+xml", | |
| "au" = "audio/basic", | |
| "avi" = "video/x-msvideo", | |
| "axs" = "application/olescript", | |
| "bas" = "text/plain", | |
| "bcpio" = "application/x-bcpio", | |
| "bin" = "application/octet-stream", | |
| "bmp" = "image/bmp", | |
| "c" = "text/plain", | |
| "cc" = "text/plain", | |
| "ccad" = "application/clariscad", | |
| "cab" = "application/octet-stream", | |
| "calx" = "application/vnd.ms-office.calx", | |
| "cat" = "application/vnd.ms-pki.seccat", | |
| "cdf" = "application/cdf", | |
| "chm" = "application/octet-stream", | |
| "class" = "application/java", | |
| "clp" = "application/x-msclip", | |
| "cmx" = "image/x-cmx", | |
| "cnf" = "text/plain", | |
| "cod" = "image/cis-cod", | |
| "cpio" = "application/x-cpio", | |
| "cpp" = "text/plain", | |
| "cpt" = "application/mac-compactpro", | |
| "crd" = "application/x-mscardfile", | |
| "crl" = "application/pkix-crl", | |
| "crt" = "application/x-x509-ca-cert", | |
| "csh" = "application/x-csh", | |
| "css" = "text/css", | |
| "csv" = "application/octet-stream", | |
| "cur" = "application/octet-stream", | |
| "dcr" = "application/x-director", | |
| "deploy" = "application/octet-stream", | |
| "der" = "application/x-x509-ca-cert", | |
| "dib" = "image/bmp", | |
| "dir" = "application/x-director", | |
| "disco" = "text/xml", | |
| "dll" = "application/x-msdownload", | |
| "dll.config" = "text/xml", | |
| "dlm" = "text/dlm", | |
| "dms" = "application/octet-stream", | |
| "doc" = "application/msword", | |
| "docm" = "application/vnd.ms-word.document.macroEnabled.12", | |
| "docx" = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", | |
| "dot" = "application/msword", | |
| "dotm" = "application/vnd.ms-word.template.macroEnabled.12", | |
| "dotx" = "application/vnd.openxmlformats-officedocument.wordprocessingml.template", | |
| "drw" = "application/drafting", | |
| "dsp" = "application/octet-stream", | |
| "dtd" = "text/xml", | |
| "dvi" = "application/x-dvi", | |
| "dwf" = "drawing/x-dwf", | |
| "dwg" = "application/acad", | |
| "dwp" = "application/octet-stream", | |
| "dxf" = "application/dxf", | |
| "dxr" = "application/x-director", | |
| "eml" = "message/rfc822", | |
| "emz" = "application/octet-stream", | |
| "eot" = "application/octet-stream", | |
| "eps" = "application/postscript", | |
| "etx" = "text/x-setext", | |
| "evy" = "application/envoy", | |
| "exe" = "application/octet-stream", | |
| "exe.config" = "text/xml", | |
| "ez" = "application/andrew-inset", | |
| "f" = "text/plain", | |
| "f90" ="text/plain", | |
| "fdf" = "application/vnd.fdf", | |
| "fif" = "application/fractals", | |
| "fla" = "application/octet-stream", | |
| "fli" = "video/x-fli", | |
| "flr" = "x-world/x-vrml", | |
| "flv" = "video/x-flv", | |
| "gif" = "image/gif", | |
| "gtar" = "application/x-gtar", | |
| "gz" = "application/x-gzip", | |
| "h" = "text/plain", | |
| "hdf" = "application/x-hdf", | |
| "hdml" = "text/x-hdml", | |
| "hh" = "text/plain", | |
| "hhc" = "application/x-oleobject", | |
| "hhk" = "application/octet-stream", | |
| "hhp" = "application/octet-stream", | |
| "hlp" = "application/winhlp", | |
| "hqx" = "application/mac-binhex40", | |
| "hta" = "application/hta", | |
| "htc" = "text/x-component", | |
| "htm" = "text/html", | |
| "html" = "text/html", | |
| "htt" = "text/webviewhtml", | |
| "hxt" = "text/html", | |
| "ice" = "x-conference/x-cooltalk", | |
| "ico" = "image/x-icon", | |
| "ics" = "application/octet-stream", | |
| "ief" = "image/ief", | |
| "iges" ="model/iges", | |
| "igs" ="model/iges", | |
| "iii" = "application/x-iphone", | |
| "inf" = "application/octet-stream", | |
| "ins" = "application/x-internet-signup", | |
| "ips" ="application/x-ipscript", | |
| "ipx" ="application/x-ipix", | |
| "isp" = "application/x-internet-signup", | |
| "IVF" = "video/x-ivf", | |
| "jar" = "application/java-archive", | |
| "java" = "application/octet-stream", | |
| "jck" = "application/liquidmotion", | |
| "jcz" = "application/liquidmotion", | |
| "jfif" = "image/pjpeg", | |
| "jpb" = "application/octet-stream", | |
| "jpe" = "image/jpeg", | |
| "jpeg" = "image/jpeg", | |
| "jpg" = "image/jpeg", | |
| "js" = "application/x-javascript", | |
| "jsx" = "text/jscript", | |
| "kar" = "audio/midi", | |
| "kml" = "application/vnd.google-earth.kml+xml", | |
| "kmz" = "application/vnd.google-earth.kmz", | |
| "latex" = "application/x-latex", | |
| "lha" = "application/octet-stream", | |
| "lit" = "application/x-ms-reader", | |
| "lpk" = "application/octet-stream", | |
| "lsf" = "video/x-la-asf", | |
| "lsp" = "application/x-lisp", | |
| "lsx" = "video/x-la-asf", | |
| "lzh" = "application/octet-stream", | |
| "m" = "text/plain", | |
| "m13" = "application/x-msmediaview", | |
| "m14" = "application/x-msmediaview", | |
| "m1v" = "video/mpeg", | |
| "m3u" = "audio/x-mpegurl", | |
| "m4v" = "video/mp4", | |
| "man" = "application/x-troff-man", | |
| "manifest" = "application/x-ms-manifest", | |
| "map" = "text/plain", | |
| "mdb" = "application/x-msaccess", | |
| "mdp" = "application/octet-stream", | |
| "me" = "application/x-troff-me", | |
| "mesh" = "model/mesh", | |
| "mht" = "message/rfc822", | |
| "mhtml" = "message/rfc822", | |
| "mid" = "audio/midi", | |
| "midi" = "audio/midi", | |
| "mif" = "application/vnd.mif", | |
| "mime" = "www/mime", | |
| "mix" = "application/octet-stream", | |
| "mmf" = "application/x-smaf", | |
| "mno" = "text/xml", | |
| "mny" = "application/x-msmoney", | |
| "mov" = "video/quicktime", | |
| "movie" = "video/x-sgi-movie", | |
| "mp2" = "audio/mpeg", | |
| "mp3" = "audio/mpeg", | |
| "mp4" = "video/mp4", | |
| "mpa" = "video/mpeg", | |
| "mpe" = "video/mpeg", | |
| "mpeg" = "video/mpeg", | |
| "mpg" = "video/mpeg", | |
| "mpga" = "audio/mpeg", | |
| "mpp" = "application/vnd.ms-project", | |
| "mpv2" = "video/mpeg", | |
| "ms" = "application/x-troff-ms", | |
| "msh" = "model/mesh", | |
| "msi" = "application/octet-stream", | |
| "mso" = "application/octet-stream", | |
| "mvb" = "application/x-msmediaview", | |
| "mvc" = "application/x-miva-compiled", | |
| "nc" = "application/x-netcdf", | |
| "nsc" = "video/x-ms-asf", | |
| "nws" = "message/rfc822", | |
| "ocx" = "application/octet-stream", | |
| "oda" = "application/oda", | |
| "odc" = "text/x-ms-odc", | |
| "ods" = "application/oleobject", | |
| "one" = "application/onenote", | |
| "onea" = "application/onenote", | |
| "onepkg" = "application/onenote", | |
| "onetmp" = "application/onenote", | |
| "onetoc" = "application/onenote", | |
| "onetoc2" = "application/onenote", | |
| "p10" = "application/pkcs10", | |
| "p12" = "application/x-pkcs12", | |
| "p7b" = "application/x-pkcs7-certificates", | |
| "p7c" = "application/pkcs7-mime", | |
| "p7m" = "application/pkcs7-mime", | |
| "p7r" = "application/x-pkcs7-certreqresp", | |
| "p7s" = "application/pkcs7-signature", | |
| "pdb" = "chemical/x-pdb", | |
| "pbm" = "image/x-portable-bitmap", | |
| "pcx" = "application/octet-stream", | |
| "pcz" = "application/octet-stream", | |
| "pdf" = "application/pdf", | |
| "pfb" = "application/octet-stream", | |
| "pfm" = "application/octet-stream", | |
| "pfx" = "application/x-pkcs12", | |
| "pgm" = "image/x-portable-graymap", | |
| "pgn" = "application/x-chess-pgn", | |
| "php" = "redirect/php", | |
| "pko" = "application/vnd.ms-pki.pko", | |
| "pma" = "application/x-perfmon", | |
| "pmc" = "application/x-perfmon", | |
| "pml" = "application/x-perfmon", | |
| "pmr" = "application/x-perfmon", | |
| "pmw" = "application/x-perfmon", | |
| "png" = "image/png", | |
| "pnm" = "image/x-portable-anymap", | |
| "pnz" = "image/png", | |
| "pot" = "application/mspowerpoint", | |
| "potm" = "application/vnd.ms-powerpoint.template.macroEnabled.12", | |
| "potx" = "application/vnd.openxmlformats-officedocument.presentationml.template", | |
| "ppam" = "application/vnd.ms-powerpoint.addin.macroEnabled.12", | |
| "ppm" = "image/x-portable-pixmap", | |
| "pps" = "application/mspowerpoint", | |
| "ppsm" = "application/vnd.ms-powerpoint.slideshow.macroEnabled.12", | |
| "ppsx" = "application/vnd.openxmlformats-officedocument.presentationml.slideshow", | |
| "ppt" = "application/mspowerpoint", | |
| "pptm" = "application/vnd.ms-powerpoint.presentation.macroEnabled.12", | |
| "pptx" = "application/vnd.openxmlformats-officedocument.presentationml.presentation", | |
| "ppz" = "application/mspowerpoint", | |
| "pre" = "application/x-freelance", | |
| "prf" = "application/pics-rules", | |
| "prm" = "application/octet-stream", | |
| "prt" = "application/pro_eng", | |
| "prx" = "application/octet-stream", | |
| "ps" = "application/postscript", | |
| "psd" = "application/octet-stream", | |
| "psm" = "application/octet-stream", | |
| "psp" = "application/octet-stream", | |
| "pub" = "application/x-mspublisher", | |
| "qt" = "video/quicktime", | |
| "qtl" = "application/x-quicktimeplayer", | |
| "qxd" = "application/octet-stream", | |
| "ra" = "audio/x-realaudio", | |
| "ram" = "audio/x-pn-realaudio", | |
| "rar" = "application/octet-stream", | |
| "ras" = "image/cmu-raster", | |
| "rf" = "image/vnd.rn-realflash", | |
| "rgb" = "image/x-rgb", | |
| "rm" = "application/x=pn-realadio", | |
| "rmi" = "audio/midi", | |
| "roff" = "application/x-troff", | |
| "rpm" = "audio/x-pn-realaudio-plugin", | |
| "rtf" = "text/rtf", | |
| "rtx" = "text/richtext", | |
| "scd" = "application/x-msschedule", | |
| "scm" = "application/x-lotusscreencam", | |
| "sct" = "text/scriptlet", | |
| "sea" = "application/octet-stream", | |
| "set" = "application/set", | |
| "setpay" = "application/set-payment-initiation", | |
| "setreg" = "application/set-registration-initiation", | |
| "sgm" = "text/sgml", | |
| "sgml" = "text/sgml", | |
| "sh" = "application/x-sh", | |
| "shar" = "application/x-shar", | |
| "silo" = "model/mesh", | |
| "sit" = "application/x-stuffit", | |
| "skd" = "application/x-koan", | |
| "skm" = "application/x-koan", | |
| "skp" = "application/x-koan", | |
| "skt" = "application/x-koan", | |
| "sldm" = "application/vnd.ms-powerpoint.slide.macroEnabled.12", | |
| "sldx" = "application/vnd.openxmlformats-officedocument.presentationml.slide", | |
| "smd" = "audio/x-smd", | |
| "smi" = "application/smil", | |
| "smil" = "application/smil", | |
| "smx" = "audio/x-smd", | |
| "smz" = "audio/x-smd", | |
| "snd" = "audio/basic", | |
| "snp" = "application/octet-stream", | |
| "sol" ="application/solids", | |
| "spc" = "application/x-pkcs7-certificates", | |
| "spl" = "application/x-futuresplash", | |
| "src" = "application/x-wais-source", | |
| "ssm" = "application/streamingmedia", | |
| "sst" = "application/vnd.ms-pki.certstore", | |
| "step" ="application/STEP", | |
| "stl" = "application/SLA", | |
| "stp" = "application/STEP", | |
| "sv4cpio" = "application/x-sv4cpio", | |
| "sv4crc" = "application/x-sv4crc", | |
| "svg" = "image/svg xml", | |
| "swf" = "application/x-shockwave-flash", | |
| "t" = "application/x-troff", | |
| "tar" = "application/x-tar", | |
| "tcl" = "application/x-tcl", | |
| "tex" = "application/x-tex", | |
| "texi" = "application/x-texinfo", | |
| "texinfo" = "application/x-texinfo", | |
| "tgz" = "application/x-compressed", | |
| "thmx" = "application/vnd.ms-officetheme", | |
| "thn" = "application/octet-stream", | |
| "tif" = "image/tiff", | |
| "tiff" = "image/tiff", | |
| "toc" = "application/octet-stream", | |
| "tr" = "application/x-troff", | |
| "trm" = "application/x-msterminal", | |
| "tsi" = "audio/TSP-audio", | |
| "tsp" = "application/dsptype", | |
| "tsv" = "text/tab-separated-values", | |
| "ttf" = "application/octet-stream", | |
| "txt" = "text/plain", | |
| "u32" = "application/octet-stream", | |
| "uls" = "text/iuls", | |
| "unv" = "application/i-deas", | |
| "ustar" = "application/x-ustar", | |
| "vbs" = "text/vbscript", | |
| "vcd" = "application/x-cdlink", | |
| "vcf" = "text/vcard", | |
| "vcs" = "text/calendar", | |
| "vda" = "application/vda", | |
| "vdx" = "application/vnd.ms-visio.viewer", | |
| "viv" = "video/vnd.vivo", | |
| "vivo" = "video/vnd.vivo", | |
| "vml" = "text/xml", | |
| "vrml" = "model/vrml", | |
| "vsd" = "application/vnd.visio", | |
| "vss" = "application/vnd.visio", | |
| "vst" = "application/vnd.visio", | |
| "vsto" = "application/x-ms-vsto", | |
| "vsw" = "application/vnd.visio", | |
| "vsx" = "application/vnd.visio", | |
| "vtx" = "application/vnd.visio", | |
| "wav" = "audio/x-wav", | |
| "wax" = "audio/x-ms-wax", | |
| "wbmp" = "image/vnd.wap.wbmp", | |
| "wcm" = "application/vnd.ms-works", | |
| "wdb" = "application/vnd.ms-works", | |
| "wks" = "application/vnd.ms-works", | |
| "wm" = "video/x-ms-wm", | |
| "wma" = "audio/x-ms-wma", | |
| "wmd" = "application/x-ms-wmd", | |
| "wmf" = "application/x-msmetafile", | |
| "wml" = "text/vnd.wap.wml", | |
| "wmlc" = "application/vnd.wap.wmlc", | |
| "wmls" = "text/vnd.wap.wmlscript", | |
| "wmlsc" = "application/vnd.wap.wmlscriptc", | |
| "wmp" = "video/x-ms-wmp", | |
| "wmv" = "video/x-ms-wmv", | |
| "wmx" = "video/x-ms-wmx", | |
| "wmz" = "application/x-ms-wmz", | |
| "wps" = "application/vnd.ms-works", | |
| "wri" = "application/x-mswrite", | |
| "wrl" ="model/vrml", | |
| "wrz" = "x-world/x-vrml", | |
| "wsdl" = "text/xml", | |
| "wvx" = "video/x-ms-wvx", | |
| "x" = "application/directx", | |
| "xaf" = "x-world/x-vrml", | |
| "xaml" = "application/xaml+xml", | |
| "xap" = "application/x-silverlight-app", | |
| "xbap" = "application/x-ms-xbap", | |
| "xbm" = "image/x-xbitmap", | |
| "xdr" = "text/plain", | |
| "xla" = "application/vnd.ms-excel", | |
| "xlam" = "application/vnd.ms-excel.addin.macroEnabled.12", | |
| "xlc" = "application/vnd.ms-excel", | |
| "xll" = "application/vnd.ms-excel", | |
| "xlm" = "application/vnd.ms-excel", | |
| "xls" = "application/vnd.ms-excel", | |
| "xlsb" = "application/vnd.ms-excel.sheet.binary.macroEnabled.12", | |
| "xlsm" = "application/vnd.ms-excel.sheet.macroEnabled.12", | |
| "xlsx" = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", | |
| "xlt" = "application/vnd.ms-excel", | |
| "xltm" = "application/vnd.ms-excel.template.macroEnabled.12", | |
| "xltx" = "application/vnd.openxmlformats-officedocument.spreadsheetml.template", | |
| "xlw" = "application/vnd.ms-excel", | |
| "xml" = "text/xml", | |
| "xof" = "x-world/x-vrml", | |
| "xpi" = "application/x-xpinstall", | |
| "xpm" = "image/x-xpixmap", | |
| "xps" = "application/vnd.ms-xpsdocument", | |
| "xsd" = "text/xml", | |
| "xsf" = "text/xml", | |
| "xsl" = "text/xml", | |
| "xslt" = "text/xml", | |
| "xsn" = "application/octet-stream", | |
| "xtp" = "application/octet-stream", | |
| "xwd" = "image/x-xwindowdump", | |
| "xyz" = "chemical/x-pdb", | |
| "z" = "application/x-compress", | |
| "zip" = "application/zip"}; | |
| if (ArrayLen(Arguments) GTE 1 AND ListLen(arguments[1],".") GT 1) { | |
| fileExtension = trim(ListLast(arguments[1],".")); | |
| } | |
| if(len(fileExtension) AND structKeyExists(mimeStruct, fileExtension)){ | |
| return mimeStruct[fileExtension]; | |
| } else { | |
| return "application/unknown"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment