Difference between revisions of "Ns guesstype"

From AOLserver Wiki
Jump to navigation Jump to search
(imported from WiKit id 572)
 
Line 81: Line 81:
 
* .text  returns "text/plain"
 
* .text  returns "text/plain"
 
* .tgz    returns "application/x-compressed"
 
* .tgz    returns "application/x-compressed"
* .tif    returns "image/tiff"
+
* .tif    returns "image/tiff" [http://www.cartesianinc.com/Products/View/TIFF/ TIFF viewers]
* .tiff  returns "image/tiff"
+
* .tiff  returns "image/tiff" [http://www.cartesianinc.com/Products/View/TIFF/ TIFF viewers]
 
* .txt    returns "text/plain"
 
* .txt    returns "text/plain"
 
* .xbm    returns "image/x-xbitmap"
 
* .xbm    returns "image/x-xbitmap"

Revision as of 15:37, 20 March 2006

Man page: http://aolserver.com/docs/tcl/ns_guesstype.html


NAME

ns_guesstype - Lookup MIME type based on file extension.

SYNOPSIS

ns_guesstype filename

DESCRIPTION

This command guesses and returns the MIME type of a file, based on the extension of filename. A large set of default extension to MIME type mappings is built into the command:
  • .adp returns "text/html; charset=iso-8859-1"
  • .dci returns "text/html; charset=iso-8859-1"
  • .htm returns "text/html; charset=iso-8859-1"
  • .html returns "text/html; charset=iso-8859-1"
  • .sht returns "text/html; charset=iso-8859-1"
  • .shtml returns "text/html; charset=iso-8859-1"
  • .ai returns "application/postscript"
  • .aif returns "audio/aiff"
  • .aifc returns "audio/aiff"
  • .aiff returns "audio/aiff"
  • .ani returns "application/x-navi-animation"
  • .art returns "image/x-art"
  • .au returns "audio/basic"
  • .avi returns "video/x-msvideo"
  • .bin returns "application/x-macbinary"
  • .bmp returns "image/bmp"
  • .css returns "text/css"
  • .csv returns "application/csv"
  • .dcr returns "application/x-director"
  • .dir returns "application/x-director"
  • .dp returns "application/commonground"
  • .dxr returns "application/x-director"
  • .elm returns "text/plain"
  • .eml returns "text/plain"
  • .exe returns "application/octet-stream"
  • .gbt returns "text/plain"
  • .gif returns "image/gif"
  • .gz returns "application/x-compressed"
  • .hqx returns "application/mac-binhex40"
  • .jfif returns "image/jpeg"
  • .jpe returns "image/jpeg"
  • .jpg returns "image/jpeg"
  • .jpeg returns "image/jpeg"
  • .js returns "application/x-javascript"
  • .ls returns "application/x-javascript"
  • .map returns "application/x-navimap"
  • .mid returns "audio/x-midi"
  • .midi returns "audio/x-midi"
  • .mocha returns "application/x-javascript"
  • .mov returns "video/quicktime"
  • .mpe returns "video/mpeg"
  • .mpeg returns "video/mpeg"
  • .mpg returns "video/mpeg"
  • .nvd returns "application/x-navidoc"
  • .nvm returns "application/x-navimap"
  • .pbm returns "image/x-portable-bitmap"
  • .pdf returns "application/pdf"
  • .pgm returns "image/x-portable-graymap"
  • .pic returns "image/pict"
  • .pict returns "image/pict"
  • .pnm returns "image/x-portable-anymap"
  • .png returns "image/png"
  • .ps returns "application/postscript"
  • .qt returns "video/quicktime"
  • .ra returns "audio/x-pn-realaudio"
  • .ram returns "audio/x-pn-realaudio"
  • .ras returns "image/x-cmu-raster"
  • .rgb returns "image/x-rgb"
  • .rtf returns "application/rtf"
  • .sit returns "application/x-stuffit"
  • .snd returns "audio/basic"
  • .sql returns "application/x-sql"
  • .stl returns "application/x-navistyle"
  • .tar returns "application/x-tar"
  • .tcl returns "text/plain"
  • .text returns "text/plain"
  • .tgz returns "application/x-compressed"
  • .tif returns "image/tiff" TIFF viewers
  • .tiff returns "image/tiff" TIFF viewers
  • .txt returns "text/plain"
  • .xbm returns "image/x-xbitmap"
  • .xpm returns "image/x-xpixmap"
  • .xht returns "application/xhtml+xml"
  • .xhtml returns "application/xhtml+xml"
  • .xml returns "text/xml"
  • .xsl returns "text/xml"
  • .vrml returns "x-world/x-vrml"
  • .wav returns "audio/x-wav"
  • .wrl returns "x-world/x-vrml"
  • .z returns "application/x-compressed"
  • .zip returns "application/x-zip-compressed"
The MIME type returned for an extension can be overriden in the AOLserver config file, and new mappings can be added, e.g.
   ns_section "ns/mimetypes"
   ns_param  ".xls"        "application/vnd.ms-excel"      ;# Add a mapping for Excel files
   ns_param  ".sjis_html"  "text/html; charset=shift_jis"  ;# Adding a mapping, specifing charset
   ns_param  ".adp"        "text/html; charset=UTF-8"      ;# Overriding an existing mapping
The MIME type to be returned for files with unrecognized or missing extensions can also be specified in the "ns/mimetypes" section of the config file, e.g.
   ns_section "ns/mimetypes"
   ns_param  default      "*/*"  ;# MIME type for unrecognized extension.
   ns_param  noextension  "*/*"  ;# MIME type for missing extension.
If default is not configured, "*/*" will be returned for files with unrecognized extensions. If noextension is not configured, the MIME type configured as default (or "*/*") will be used.

EXAMPLES

(Assuming configured with the examples above)
   % ns_guesstype "hello.jpg"
   image/jpeg
   % ns_guesstype "hello.xls"
   application/vnd.ms-excel
   % ns_guesstype "hello.html"
   text/html; charset=iso-8859-1
   % ns_guesstype "world.adp"
   text/html; charset=UTF-8
   % ns_guesstype "world.doc"
  • /*
   % ns_guesstype somefile
  • /*

Category Documentation - Category Core Tcl API