檔案類型判斷 MIME TYPE

要檢查檔案型態,用副檔名可不是一個好辦法,例如 movie.jpg 不見得就真的是一個 jpg 檔案,有可能是篡改副檔名的偽裝檔案,所以最準確的方法是去參考 MIME TYPE ,就可以在檔案上傳時檢測檔案的真正身分,這個方法適用任何的 Server Language (ASP.NET, PHP, ColdFusion, JSP…)。 

Form Mime Type List

MIME Type                          Extension
----------------------------------+----------------------------------
animation/narrative                nml
application/activemessage
application/andrew-inset
application/applefile
application/atomicmail
application/dca-rft
application/dec-dx
application/dsptype                tsp
application/fastman                lcc
application/font-tdpfr             pfr pfr
application/futuresplash           spl
application/mac-binhex40           hqx
application/mac-compactpro         cpt
application/macwriteii
application/mspowerpoint           pot pps ppt ppz
application/msword
application/news-message-id
application/news-transmission
application/octet-stream           bin class dms exe jar sea
application/oda                    oda
application/pdf                    pdf
application/postscript             ai eps ps
application/remote-printing
application/rtf                    rtf
application/slate
application/smil                   smi
application/softvision             svi
application/t-time                 ttz
application/wita
application/wordperfect5.1
application/x-authorware-bin       aab
application/x-authorware-map       aam
application/x-authorware-seg       aas
application/x-bcpio                bcpio
application/x-bzip2                bz2
application/x-calquick             cqk
application/x-cdlink               vcd
application/x-cnc                  ccn
application/x-cocoa                cco
application/x-compress             Z
application/x-cpio                 cpio
application/x-csh                  csh
application/x-director             dcr dir dxr
application/x-dvi                  dvi
application/x-excel                xls
application/x-expandedbook         ebk
application/x-gtar                 gtar
application/x-gzip                 gz
application/x-hdf                  hdf
application/x-httpd-cgi            cgi
application/x-javascript           js ls mocha
application/x-koan                 skd skm skp skt
application/x-latex                latex
application/x-lzh                  lha lzh
application/x-mapserver            mps
application/x-mascot               mct
application/x-mif                  mif
application/x-netcdf               cdf nc
application/x-ns-proxy-auto-config pac
application/x-pixelscooter         mpp
application/x-sh                   sh
application/x-shar                 shar
application/x-shockwave-flash      swf
application/x-sprite               spr sprite
application/x-spt                  spt
application/x-stuffit              sit
application/x-sv4cpio              sv4cpio
application/x-sv4crc               sv4crc
application/x-tar                  tar tgz
application/x-tcl                  tcl
application/x-tex                  tex
application/x-texinfo              texi texinfo
application/x-troff                roff t tr
application/x-troff-man            man
application/x-troff-me             me
application/x-troff-ms             ms
application/x-ustar                ustar
application/x-wais-source          src
application/x-xdma                 xdm xdma
application/zip                    zip
audio/basic                        au snd
audio/echospeech                   es
audio/midi                         kar mid midi
audio/mpeg                         mp2 mp3 mpga
audio/tsplayer                     tsi
audio/vnd.rn-realaudio             ra
audio/voxware                      vox
audio/x-aiff                       aif aifc aiff
audio/x-bamba                      aba
audio/x-chacha                     cha
audio/x-mio                        mio
audio/x-pn-realaudio               ram rm
audio/x-pn-realaudio-plugin        rpm
audio/x-twinvq                     vqf vql
audio/x-twinvq-plugin              vqe
audio/x-wav                        wav
chemical/x-csml                    csm
chemical/x-embl-dl-nucleotide      emb
chemical/x-gaussian-input          gau
chemical/x-mdl-molfile             mol
chemical/x-mopac-input             mop
chemical/x-pdb                     pdb
chemical/x-xyz                     xyz
i-world/i-vrml                     ivr
image/bmp                          bmp
image/fif                          fif
image/gif                          gif
image/ief                          ief
image/jpeg                         jpe jpeg jpg
image/png                          png
image/tiff                         tif tiff
image/vasa                         mcf
image/vnd.rn-realpix               rp
image/x-cmu-raster                 ras
image/x-freehand                   fh fh4 fh5 fh7 fhc
image/x-jps                        jps
image/x-portable-anymap            pnm
image/x-portable-bitmap            pbm
image/x-portable-graymap           pgm
image/x-portable-pixmap            ppm
image/x-rgb                        rgb
image/x-xbitmap                    xbm
image/x-xpixmap                    xpm
image/x-xres                       swx
image/x-xwindowdump                xwd
message/external-body
message/news
message/partial
message/rfc822
multipart/alternative
multipart/appledouble
multipart/digest
multipart/mixed
multipart/parallel
plugin/listenup                    ptlk
plugin/wanimate                    waf wan
text/css                           css
text/html                          htm html
text/plain                         txt
text/richtext                      rtx
text/tab-separated-values          tsv
text/vnd.rn-realtext               rt
text/x-setext                      etx
text/x-sgml                        sgm sgml
text/x-speech                      talk
text/x-vcard                       vcf
text/xml                           xml
text/xsl                           xsl
video/mpeg                         mpe mpeg mpg
video/quicktime                    mov qt
video/vnd.rn-realvideo             rv
video/vnd.vivo                     viv vivo
video/x-bamba                      vba
video/x-ms-asf                     asf asx
video/x-msvideo                    avi
video/x-qmsys                      qm
video/x-sgi-movie                  movie
video/x-tango                      tgo
video/x-vif                        vif
workbook/formulaone                vts
world/x-panoramix                  pan
x-conference/x-cooltalk            ice
x-world/x-d96                      d96 mus
x-world/x-svr                      svr
x-world/x-vrml                     vrml wrl
x-world/x-vrt                      vrt
本篇發表於 Tips 與標籤於 anistar固定網址書籤。
本文引用:
文章內容為ANISTAR BLOG所有,引用分享請以鏈結形式註明出處與原始作者。

關於 anistar

現任:台灣區 Yahoo! 專長: Objective C、iOS SDK、Android SDK、Flex 4、RIA、ActrionScript 3、HTML5、CSS3、JQuery、JQuery Mobile、C++、PHP、MySQL...等整合運用。 著作:《Run!PC雜誌》專欄作家、《CADesigner雜誌》專欄作家、《Flash CS3 Professional ActionScript 3.0 打造互動設計力與美》、《新一代互動體驗Flex+AIR程式開發》。 認證:Macromedia Certified Instructor in ColdFusion    Adobe Certified Expert in Photoshop    Adobe Certified Instructor in Flex

2 則迴響於《檔案類型判斷 MIME TYPE

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *