Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 21.90 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Does PHP have a function that returns the correct file extension given a valid content type?
  2. <?php
  3. function getFileExtension($contentType)
  4. {
  5.     if ($contentType === 'image/png')
  6.     {
  7.         return '.png';
  8.     }
  9.     elseif ($contentType === 'image/jpg')
  10.     {
  11.         return '.jpg';
  12.     }
  13.     elseif ($contentType === 'application/zip')
  14.     {
  15.         return '.zip';
  16.     }
  17.     else
  18.     {
  19.         return FALSE;
  20.     }
  21. }
  22.        
  23. <?php
  24. function getFileExtension($contentType)
  25. {
  26.     $pieces = explode('/', $contentType);
  27.     return '.' . array_pop($pieces);
  28. }
  29.        
  30. <?php
  31. class AppUtil
  32. {
  33.     public static function FileExt($contentType)
  34.     {
  35.         $map = array(
  36.             'application/pdf'   => '.pdf',
  37.             'application/zip'   => '.zip',
  38.             'image/gif'         => '.gif',
  39.             'image/jpeg'        => '.jpg',
  40.             'image/png'         => '.png',
  41.             'text/css'          => '.css',
  42.             'text/html'         => '.html',
  43.             'text/javascript'   => '.js',
  44.             'text/plain'        => '.txt',
  45.             'text/xml'          => '.xml',
  46.         );
  47.         if (isset($map[$contentType]))
  48.         {
  49.             return $map[$contentType];
  50.         }
  51.  
  52.         // HACKISH CATCH ALL (WHICH IN MY CASE IS
  53.         // PREFERRED OVER THROWING AN EXCEPTION)
  54.         $pieces = explode('/', $contentType);
  55.         return '.' . array_pop($pieces);
  56.     }
  57. }
  58.  
  59. echo AppUtil::FileExt('application/zip'); // prints '.zip'
  60.        
  61. <?php
  62. // DEFINITIVE "CONTENT TYPE TO FILE EXTENSION" MAPPINGS
  63. $definitive = array (
  64.   'application/x-authorware-bin' => '.aab',
  65.   'application/x-authorware-map' => '.aam',
  66.   'application/x-authorware-seg' => '.aas',
  67.   'text/vnd.abc' => '.abc',
  68.   'video/animaflex' => '.afl',
  69.   'application/x-aim' => '.aim',
  70.   'text/x-audiosoft-intra' => '.aip',
  71.   'application/x-navi-animation' => '.ani',
  72.   'application/x-nokia-9000-communicator-add-on-software' => '.aos',
  73.   'application/mime' => '.aps',
  74.   'application/arj' => '.arj',
  75.   'image/x-jg' => '.art',
  76.   'text/asp' => '.asp',
  77.   'application/x-mplayer2' => '.asx',
  78.   'video/x-ms-asf-plugin' => '.asx',
  79.   'audio/x-au' => '.au',
  80.   'application/x-troff-msvideo' => '.avi',
  81.   'video/avi' => '.avi',
  82.   'video/msvideo' => '.avi',
  83.   'video/x-msvideo' => '.avi',
  84.   'video/avs-video' => '.avs',
  85.   'application/x-bcpio' => '.bcpio',
  86.   'application/mac-binary' => '.bin',
  87.   'application/macbinary' => '.bin',
  88.   'application/x-binary' => '.bin',
  89.   'application/x-macbinary' => '.bin',
  90.   'image/x-windows-bmp' => '.bmp',
  91.   'application/x-bzip' => '.bz',
  92.   'application/vnd.ms-pki.seccat' => '.cat',
  93.   'application/clariscad' => '.ccad',
  94.   'application/x-cocoa' => '.cco',
  95.   'application/cdf' => '.cdf',
  96.   'application/x-cdf' => '.cdf',
  97.   'application/java' => '.class',
  98.   'application/java-byte-code' => '.class',
  99.   'application/x-java-class' => '.class',
  100.   'application/x-cpio' => '.cpio',
  101.   'application/mac-compactpro' => '.cpt',
  102.   'application/x-compactpro' => '.cpt',
  103.   'application/x-cpt' => '.cpt',
  104.   'application/pkcs-crl' => '.crl',
  105.   'application/pkix-crl' => '.crl',
  106.   'application/x-x509-user-cert' => '.crt',
  107.   'application/x-csh' => '.csh',
  108.   'text/x-script.csh' => '.csh',
  109.   'application/x-pointplus' => '.css',
  110.   'text/css' => '.css',
  111.   'application/x-deepv' => '.deepv',
  112.   'video/dl' => '.dl',
  113.   'video/x-dl' => '.dl',
  114.   'application/commonground' => '.dp',
  115.   'application/drafting' => '.drw',
  116.   'application/x-dvi' => '.dvi',
  117.   'drawing/x-dwf (old)' => '.dwf',
  118.   'model/vnd.dwf' => '.dwf',
  119.   'application/acad' => '.dwg',
  120.   'application/dxf' => '.dxf',
  121.   'text/x-script.elisp' => '.el',
  122.   'application/x-bytecode.elisp (compiled elisp)' => '.elc',
  123.   'application/x-elc' => '.elc',
  124.   'application/x-esrehber' => '.es',
  125.   'text/x-setext' => '.etx',
  126.   'application/envoy' => '.evy',
  127.   'application/vnd.fdf' => '.fdf',
  128.   'application/fractals' => '.fif',
  129.   'image/fif' => '.fif',
  130.   'video/fli' => '.fli',
  131.   'video/x-fli' => '.fli',
  132.   'text/vnd.fmi.flexstor' => '.flx',
  133.   'video/x-atomic3d-feature' => '.fmf',
  134.   'image/vnd.fpx' => '.fpx',
  135.   'image/vnd.net-fpx' => '.fpx',
  136.   'application/freeloader' => '.frl',
  137.   'image/g3fax' => '.g3',
  138.   'image/gif' => '.gif',
  139.   'video/gl' => '.gl',
  140.   'video/x-gl' => '.gl',
  141.   'application/x-gsp' => '.gsp',
  142.   'application/x-gss' => '.gss',
  143.   'application/x-gtar' => '.gtar',
  144.   'multipart/x-gzip' => '.gzip',
  145.   'application/x-hdf' => '.hdf',
  146.   'text/x-script' => '.hlb',
  147.   'application/hlp' => '.hlp',
  148.   'application/x-winhelp' => '.hlp',
  149.   'application/binhex' => '.hqx',
  150.   'application/binhex4' => '.hqx',
  151.   'application/mac-binhex' => '.hqx',
  152.   'application/mac-binhex40' => '.hqx',
  153.   'application/x-binhex40' => '.hqx',
  154.   'application/x-mac-binhex40' => '.hqx',
  155.   'application/hta' => '.hta',
  156.   'text/x-component' => '.htc',
  157.   'text/webviewhtml' => '.htt',
  158.   'x-conference/x-cooltalk' => '.ice ',
  159.   'image/x-icon' => '.ico',
  160.   'application/x-ima' => '.ima',
  161.   'application/x-httpd-imap' => '.imap',
  162.   'application/inf' => '.inf ',
  163.   'application/x-internett-signup' => '.ins',
  164.   'application/x-ip2' => '.ip ',
  165.   'video/x-isvideo' => '.isu',
  166.   'audio/it' => '.it',
  167.   'application/x-inventor' => '.iv',
  168.   'i-world/i-vrml' => '.ivr',
  169.   'application/x-livescreen' => '.ivy',
  170.   'audio/x-jam' => '.jam ',
  171.   'application/x-java-commerce' => '.jcm ',
  172.   'image/x-jps' => '.jps',
  173.   'application/x-javascript' => '.js ',
  174.   'image/jutvision' => '.jut',
  175.   'music/x-karaoke' => '.kar',
  176.   'application/x-ksh' => '.ksh',
  177.   'text/x-script.ksh' => '.ksh',
  178.   'audio/x-liveaudio' => '.lam',
  179.   'application/lha' => '.lha',
  180.   'application/x-lha' => '.lha',
  181.   'application/x-lisp' => '.lsp ',
  182.   'text/x-script.lisp' => '.lsp ',
  183.   'text/x-la-asf' => '.lsx',
  184.   'application/x-lzh' => '.lzh',
  185.   'application/lzx' => '.lzx',
  186.   'application/x-lzx' => '.lzx',
  187.   'text/x-m' => '.m',
  188.   'audio/x-mpequrl' => '.m3u ',
  189.   'application/x-troff-man' => '.man',
  190.   'application/x-navimap' => '.map',
  191.   'application/mbedlet' => '.mbd',
  192.   'application/x-magic-cap-package-1.0' => '.mc$',
  193.   'application/mcad' => '.mcd',
  194.   'application/x-mathcad' => '.mcd',
  195.   'image/vasa' => '.mcf',
  196.   'text/mcf' => '.mcf',
  197.   'application/netmc' => '.mcp',
  198.   'application/x-troff-me' => '.me ',
  199.   'application/x-frame' => '.mif',
  200.   'application/x-mif' => '.mif',
  201.   'www/mime' => '.mime ',
  202.   'audio/x-vnd.audioexplosion.mjuicemediafile' => '.mjf',
  203.   'video/x-motion-jpeg' => '.mjpg ',
  204.   'application/x-meme' => '.mm',
  205.   'audio/mod' => '.mod',
  206.   'audio/x-mod' => '.mod',
  207.   'audio/x-mpeg' => '.mp2',
  208.   'video/x-mpeq2a' => '.mp2',
  209.   'audio/mpeg3' => '.mp3',
  210.   'audio/x-mpeg-3' => '.mp3',
  211.   'application/vnd.ms-project' => '.mpp',
  212.   'application/marc' => '.mrc',
  213.   'application/x-troff-ms' => '.ms',
  214.   'application/x-vnd.audioexplosion.mzz' => '.mzz',
  215.   'application/vnd.nokia.configuration-message' => '.ncm',
  216.   'application/x-mix-transfer' => '.nix',
  217.   'application/x-conference' => '.nsc',
  218.   'application/x-navidoc' => '.nvd',
  219.   'application/oda' => '.oda',
  220.   'application/x-omc' => '.omc',
  221.   'application/x-omcdatamaker' => '.omcd',
  222.   'application/x-omcregerator' => '.omcr',
  223.   'text/x-pascal' => '.p',
  224.   'application/pkcs10' => '.p10',
  225.   'application/x-pkcs10' => '.p10',
  226.   'application/pkcs-12' => '.p12',
  227.   'application/x-pkcs12' => '.p12',
  228.   'application/x-pkcs7-signature' => '.p7a',
  229.   'application/x-pkcs7-certreqresp' => '.p7r',
  230.   'application/pkcs7-signature' => '.p7s',
  231.   'text/pascal' => '.pas',
  232.   'image/x-portable-bitmap' => '.pbm ',
  233.   'application/vnd.hp-pcl' => '.pcl',
  234.   'application/x-pcl' => '.pcl',
  235.   'image/x-pict' => '.pct',
  236.   'image/x-pcx' => '.pcx',
  237.   'application/pdf' => '.pdf',
  238.   'audio/make.my.funk' => '.pfunk',
  239.   'image/x-portable-graymap' => '.pgm',
  240.   'image/x-portable-greymap' => '.pgm',
  241.   'application/x-newton-compatible-pkg' => '.pkg',
  242.   'application/vnd.ms-pki.pko' => '.pko',
  243.   'text/x-script.perl' => '.pl',
  244.   'application/x-pixclscript' => '.plx',
  245.   'text/x-script.perl-module' => '.pm',
  246.   'application/x-portable-anymap' => '.pnm',
  247.   'image/x-portable-anymap' => '.pnm',
  248.   'model/x-pov' => '.pov',
  249.   'image/x-portable-pixmap' => '.ppm',
  250.   'application/powerpoint' => '.ppt',
  251.   'application/x-mspowerpoint' => '.ppt',
  252.   'application/x-freelance' => '.pre',
  253.   'paleovu/x-pv' => '.pvu',
  254.   'text/x-script.phyton' => '.py ',
  255.   'applicaiton/x-bytecode.python' => '.pyc ',
  256.   'audio/vnd.qcelp' => '.qcp ',
  257.   'video/x-qtc' => '.qtc',
  258.   'audio/x-realaudio' => '.ra',
  259.   'application/x-cmu-raster' => '.ras',
  260.   'image/x-cmu-raster' => '.ras',
  261.   'text/x-script.rexx' => '.rexx ',
  262.   'image/vnd.rn-realflash' => '.rf',
  263.   'image/x-rgb' => '.rgb ',
  264.   'application/vnd.rn-realmedia' => '.rm',
  265.   'audio/mid' => '.rmi',
  266.   'application/ringing-tones' => '.rng',
  267.   'application/vnd.nokia.ringing-tone' => '.rng',
  268.   'application/vnd.rn-realplayer' => '.rnx ',
  269.   'image/vnd.rn-realpix' => '.rp ',
  270.   'text/vnd.rn-realtext' => '.rt',
  271.   'application/x-rtf' => '.rtf',
  272.   'video/vnd.rn-realvideo' => '.rv',
  273.   'audio/s3m' => '.s3m ',
  274.   'application/x-lotusscreencam' => '.scm',
  275.   'text/x-script.guile' => '.scm',
  276.   'text/x-script.scheme' => '.scm',
  277.   'video/x-scm' => '.scm',
  278.   'application/sdp' => '.sdp ',
  279.   'application/x-sdp' => '.sdp ',
  280.   'application/sounder' => '.sdr',
  281.   'application/sea' => '.sea',
  282.   'application/x-sea' => '.sea',
  283.   'application/set' => '.set',
  284.   'application/x-sh' => '.sh',
  285.   'text/x-script.sh' => '.sh',
  286.   'audio/x-psid' => '.sid',
  287.   'application/x-sit' => '.sit',
  288.   'application/x-stuffit' => '.sit',
  289.   'application/x-seelogo' => '.sl ',
  290.   'audio/x-adpcm' => '.snd',
  291.   'application/solids' => '.sol',
  292.   'application/x-pkcs7-certificates' => '.spc ',
  293.   'application/futuresplash' => '.spl',
  294.   'application/streamingmedia' => '.ssm ',
  295.   'application/vnd.ms-pki.certstore' => '.sst',
  296.   'application/sla' => '.stl',
  297.   'application/vnd.ms-pki.stl' => '.stl',
  298.   'application/x-navistyle' => '.stl',
  299.   'application/x-sv4cpio' => '.sv4cpio',
  300.   'application/x-sv4crc' => '.sv4crc',
  301.   'x-world/x-svr' => '.svr',
  302.   'application/x-shockwave-flash' => '.swf',
  303.   'application/x-tar' => '.tar',
  304.   'application/toolbook' => '.tbk',
  305.   'application/x-tcl' => '.tcl',
  306.   'text/x-script.tcl' => '.tcl',
  307.   'text/x-script.tcsh' => '.tcsh',
  308.   'application/x-tex' => '.tex',
  309.   'application/plain' => '.text',
  310.   'application/gnutar' => '.tgz',
  311.   'audio/tsp-audio' => '.tsi',
  312.   'application/dsptype' => '.tsp',
  313.   'audio/tsplayer' => '.tsp',
  314.   'text/tab-separated-values' => '.tsv',
  315.   'text/x-uil' => '.uil',
  316.   'application/i-deas' => '.unv',
  317.   'application/x-ustar' => '.ustar',
  318.   'multipart/x-ustar' => '.ustar',
  319.   'application/x-cdlink' => '.vcd',
  320.   'text/x-vcalendar' => '.vcs',
  321.   'application/vda' => '.vda',
  322.   'video/vdo' => '.vdo',
  323.   'application/groupwise' => '.vew ',
  324.   'application/vocaltec-media-desc' => '.vmd ',
  325.   'application/vocaltec-media-file' => '.vmf',
  326.   'audio/voc' => '.voc',
  327.   'audio/x-voc' => '.voc',
  328.   'video/vosaic' => '.vos',
  329.   'audio/voxware' => '.vox',
  330.   'audio/x-twinvq' => '.vqf',
  331.   'application/x-vrml' => '.vrml',
  332.   'x-world/x-vrt' => '.vrt',
  333.   'application/wordperfect6.1' => '.w61',
  334.   'audio/wav' => '.wav',
  335.   'audio/x-wav' => '.wav',
  336.   'application/x-qpro' => '.wb1',
  337.   'image/vnd.wap.wbmp' => '.wbmp',
  338.   'application/vnd.xara' => '.web',
  339.   'application/x-123' => '.wk1',
  340.   'windows/metafile' => '.wmf',
  341.   'text/vnd.wap.wml' => '.wml',
  342.   'application/vnd.wap.wmlc' => '.wmlc ',
  343.   'text/vnd.wap.wmlscript' => '.wmls',
  344.   'application/vnd.wap.wmlscriptc' => '.wmlsc ',
  345.   'application/x-wpwin' => '.wpd',
  346.   'application/x-lotus' => '.wq1',
  347.   'application/mswrite' => '.wri',
  348.   'application/x-wri' => '.wri',
  349.   'text/scriplet' => '.wsc',
  350.   'application/x-wintalk' => '.wtk ',
  351.   'image/x-xbitmap' => '.xbm',
  352.   'image/x-xbm' => '.xbm',
  353.   'image/xbm' => '.xbm',
  354.   'video/x-amt-demorun' => '.xdr',
  355.   'xgl/drawing' => '.xgz',
  356.   'image/vnd.xiff' => '.xif',
  357.   'audio/xm' => '.xm',
  358.   'application/xml' => '.xml',
  359.   'text/xml' => '.xml',
  360.   'xgl/movie' => '.xmz',
  361.   'application/x-vnd.ls-xpix' => '.xpix',
  362.   'image/xpm' => '.xpm',
  363.   'video/x-amt-showrun' => '.xsr',
  364.   'image/x-xwd' => '.xwd',
  365.   'image/x-xwindowdump' => '.xwd',
  366.   'application/x-compress' => '.z',
  367.   'application/x-zip-compressed' => '.zip',
  368.   'application/zip' => '.zip',
  369.   'multipart/x-zip' => '.zip',
  370.   'text/x-script.zsh' => '.zsh',
  371. );
  372.        
  373. <?php
  374. // AMBIGUOUS "CONTENT TYPE TO FILE EXTENSION" MAPPINGS
  375. $ambiguous = array (
  376.   'x-world/x-3dmf' =>
  377.   array (
  378.     0 => '.3dm',
  379.     1 => '.3dmf',
  380.     2 => '.qd3 ',
  381.     3 => '.qd3d ',
  382.   ),
  383.   'application/octet-stream' =>
  384.   array (
  385.     0 => '.a',
  386.     1 => '.arc',
  387.     2 => '.arj',
  388.     3 => '.bin',
  389.     4 => '.com',
  390.     5 => '.dump',
  391.     6 => '.exe',
  392.     7 => '.lha',
  393.     8 => '.lhx',
  394.     9 => '.lzh',
  395.     10 => '.lzx',
  396.     11 => '.o',
  397.     12 => '.psd',
  398.     13 => '.saveme',
  399.     14 => '.uu',
  400.     15 => '.zoo',
  401.   ),
  402.   'text/html' =>
  403.   array (
  404.     0 => '.acgi',
  405.     1 => '.htm',
  406.     2 => '.html',
  407.     3 => '.htmls',
  408.     4 => '.htx ',
  409.     5 => '.shtml ',
  410.   ),
  411.   'application/postscript' =>
  412.   array (
  413.     0 => '.ai',
  414.     1 => '.eps',
  415.     2 => '.ps',
  416.   ),
  417.   'audio/aiff' =>
  418.   array (
  419.     0 => '.aif',
  420.     1 => '.aifc',
  421.     2 => '.aiff',
  422.   ),
  423.   'audio/x-aiff' =>
  424.   array (
  425.     0 => '.aif',
  426.     1 => '.aifc',
  427.     2 => '.aiff',
  428.   ),
  429.   'video/x-ms-asf' =>
  430.   array (
  431.     0 => '.asf',
  432.     1 => '.asx',
  433.   ),
  434.   'text/x-asm' =>
  435.   array (
  436.     0 => '.asm',
  437.     1 => '.s',
  438.   ),
  439.   'audio/basic' =>
  440.   array (
  441.     0 => '.au',
  442.     1 => '.snd',
  443.   ),
  444.   'image/bmp' =>
  445.   array (
  446.     0 => '.bm',
  447.     1 => '.bmp',
  448.   ),
  449.   'application/book' =>
  450.   array (
  451.     0 => '.boo',
  452.     1 => '.book',
  453.   ),
  454.   'application/x-bzip2' =>
  455.   array (
  456.     0 => '.boz',
  457.     1 => '.bz2',
  458.   ),
  459.   'application/x-bsh' =>
  460.   array (
  461.     0 => '.bsh',
  462.     1 => '.sh',
  463.     2 => '.shar',
  464.   ),
  465.   'text/plain' =>
  466.   array (
  467.     0 => '.c',
  468.     1 => '.c++',
  469.     2 => '.cc',
  470.     3 => '.com',
  471.     4 => '.conf',
  472.     5 => '.cxx',
  473.     6 => '.def',
  474.     7 => '.f',
  475.     8 => '.f90',
  476.     9 => '.for',
  477.     10 => '.g',
  478.     11 => '.h',
  479.     12 => '.hh',
  480.     13 => '.idc',
  481.     14 => '.jav',
  482.     15 => '.java',
  483.     16 => '.list',
  484.     17 => '.log ',
  485.     18 => '.lst ',
  486.     19 => '.m',
  487.     20 => '.mar',
  488.     21 => '.pl',
  489.     22 => '.sdml',
  490.     23 => '.text',
  491.     24 => '.txt',
  492.   ),
  493.   'text/x-c' =>
  494.   array (
  495.     0 => '.c',
  496.     1 => '.cc',
  497.     2 => '.cpp',
  498.   ),
  499.   'application/x-netcdf' =>
  500.   array (
  501.     0 => '.cdf',
  502.     1 => '.nc',
  503.   ),
  504.   'application/pkix-cert' =>
  505.   array (
  506.     0 => '.cer',
  507.     1 => '.crt',
  508.   ),
  509.   'application/x-x509-ca-cert' =>
  510.   array (
  511.     0 => '.cer',
  512.     1 => '.crt',
  513.     2 => '.der',
  514.   ),
  515.   'application/x-chat' =>
  516.   array (
  517.     0 => '.cha',
  518.     1 => '.chat',
  519.   ),
  520.   'application/x-director' =>
  521.   array (
  522.     0 => '.dcr',
  523.     1 => '.dir',
  524.     2 => '.dxr',
  525.   ),
  526.   'video/x-dv' =>
  527.   array (
  528.     0 => '.dif',
  529.     1 => '.dv',
  530.   ),
  531.   'application/msword' =>
  532.   array (
  533.     0 => '.doc',
  534.     1 => '.dot',
  535.     2 => '.w6w',
  536.     3 => '.wiz',
  537.     4 => '.word ',
  538.   ),
  539.   'image/vnd.dwg' =>
  540.   array (
  541.     0 => '.dwg',
  542.     1 => '.dxf',
  543.     2 => '.svf',
  544.   ),
  545.   'image/x-dwg' =>
  546.   array (
  547.     0 => '.dwg',
  548.     1 => '.dxf',
  549.     2 => '.svf',
  550.   ),
  551.   'application/x-envoy' =>
  552.   array (
  553.     0 => '.env',
  554.     1 => '.evy',
  555.   ),
  556.   'text/x-fortran' =>
  557.   array (
  558.     0 => '.f',
  559.     1 => '.f77',
  560.     2 => '.f90',
  561.     3 => '.for',
  562.   ),
  563.   'image/florian' =>
  564.   array (
  565.     0 => '.flo',
  566.     1 => '.turbot',
  567.   ),
  568.   'audio/make' =>
  569.   array (
  570.     0 => '.funk',
  571.     1 => '.my',
  572.     2 => '.pfunk',
  573.   ),
  574.   'audio/x-gsm' =>
  575.   array (
  576.     0 => '.gsd',
  577.     1 => '.gsm',
  578.   ),
  579.   'application/x-compressed' =>
  580.   array (
  581.     0 => '.gz',
  582.     1 => '.tgz',
  583.     2 => '.z',
  584.     3 => '.zip',
  585.   ),
  586.   'application/x-gzip' =>
  587.   array (
  588.     0 => '.gz',
  589.     1 => '.gzip',
  590.   ),
  591.   'text/x-h' =>
  592.   array (
  593.     0 => '.h',
  594.     1 => '.hh',
  595.   ),
  596.   'application/x-helpfile' =>
  597.   array (
  598.     0 => '.help',
  599.     1 => '.hlp',
  600.   ),
  601.   'application/vnd.hp-hpgl' =>
  602.   array (
  603.     0 => '.hgl',
  604.     1 => '.hpg',
  605.     2 => '.hpgl',
  606.   ),
  607.   'image/ief' =>
  608.   array (
  609.     0 => '.ief',
  610.     1 => '.iefs',
  611.   ),
  612.   'application/iges' =>
  613.   array (
  614.     0 => '.iges',
  615.     1 => '.igs',
  616.   ),
  617.   'model/iges' =>
  618.   array (
  619.     0 => '.iges ',
  620.     1 => '.igs',
  621.   ),
  622.   'text/x-java-source' =>
  623.   array (
  624.     0 => '.jav',
  625.     1 => '.java ',
  626.   ),
  627.   'image/jpeg' =>
  628.   array (
  629.     0 => '.jfif',
  630.     1 => '.jfif-tbnl',
  631.     2 => '.jpe',
  632.     3 => '.jpeg',
  633.     4 => '.jpg ',
  634.   ),
  635.   'image/pjpeg' =>
  636.   array (
  637.     0 => '.jfif',
  638.     1 => '.jpe',
  639.     2 => '.jpeg',
  640.     3 => '.jpg ',
  641.   ),
  642.   'audio/midi' =>
  643.   array (
  644.     0 => '.kar',
  645.     1 => '.mid',
  646.     2 => '.midi',
  647.   ),
  648.   'audio/nspaudio' =>
  649.   array (
  650.     0 => '.la ',
  651.     1 => '.lma',
  652.   ),
  653.   'audio/x-nspaudio' =>
  654.   array (
  655.     0 => '.la ',
  656.     1 => '.lma',
  657.   ),
  658.   'application/x-latex' =>
  659.   array (
  660.     0 => '.latex ',
  661.     1 => '.ltx',
  662.   ),
  663.   'video/mpeg' =>
  664.   array (
  665.     0 => '.m1v',
  666.     1 => '.m2v',
  667.     2 => '.mp2',
  668.     3 => '.mp3',
  669.     4 => '.mpa',
  670.     5 => '.mpe',
  671.     6 => '.mpeg',
  672.     7 => '.mpg',
  673.   ),
  674.   'audio/mpeg' =>
  675.   array (
  676.     0 => '.m2a',
  677.     1 => '.mp2',
  678.     2 => '.mpa',
  679.     3 => '.mpg',
  680.     4 => '.mpga',
  681.   ),
  682.   'message/rfc822' =>
  683.   array (
  684.     0 => '.mht',
  685.     1 => '.mhtml',
  686.     2 => '.mime ',
  687.   ),
  688.   'application/x-midi' =>
  689.   array (
  690.     0 => '.mid',
  691.     1 => '.midi',
  692.   ),
  693.   'audio/x-mid' =>
  694.   array (
  695.     0 => '.mid',
  696.     1 => '.midi',
  697.   ),
  698.   'audio/x-midi' =>
  699.   array (
  700.     0 => '.mid',
  701.     1 => '.midi',
  702.   ),
  703.   'music/crescendo' =>
  704.   array (
  705.     0 => '.mid',
  706.     1 => '.midi',
  707.   ),
  708.   'x-music/x-midi' =>
  709.   array (
  710.     0 => '.mid',
  711.     1 => '.midi',
  712.   ),
  713.   'application/base64' =>
  714.   array (
  715.     0 => '.mm',
  716.     1 => '.mme',
  717.   ),
  718.   'video/quicktime' =>
  719.   array (
  720.     0 => '.moov',
  721.     1 => '.mov',
  722.     2 => '.qt',
  723.   ),
  724.   'video/x-sgi-movie' =>
  725.   array (
  726.     0 => '.movie',
  727.     1 => '.mv',
  728.   ),
  729.   'video/x-mpeg' =>
  730.   array (
  731.     0 => '.mp2',
  732.     1 => '.mp3',
  733.   ),
  734.   'application/x-project' =>
  735.   array (
  736.     0 => '.mpc',
  737.     1 => '.mpt',
  738.     2 => '.mpv',
  739.     3 => '.mpx',
  740.   ),
  741.   'image/naplps' =>
  742.   array (
  743.     0 => '.nap',
  744.     1 => '.naplps',
  745.   ),
  746.   'image/x-niff' =>
  747.   array (
  748.     0 => '.nif',
  749.     1 => '.niff',
  750.   ),
  751.   'application/pkcs7-mime' =>
  752.   array (
  753.     0 => '.p7c',
  754.     1 => '.p7m',
  755.   ),
  756.   'application/x-pkcs7-mime' =>
  757.   array (
  758.     0 => '.p7c',
  759.     1 => '.p7m',
  760.   ),
  761.   'application/pro_eng' =>
  762.   array (
  763.     0 => '.part ',
  764.     1 => '.prt',
  765.   ),
  766.   'chemical/x-pdb' =>
  767.   array (
  768.     0 => '.pdb',
  769.     1 => '.xyz',
  770.   ),
  771.   'image/pict' =>
  772.   array (
  773.     0 => '.pic',
  774.     1 => '.pict',
  775.   ),
  776.   'image/x-xpixmap' =>
  777.   array (
  778.     0 => '.pm',
  779.     1 => '.xpm',
  780.   ),
  781.   'application/x-pagemaker' =>
  782.   array (
  783.     0 => '.pm4 ',
  784.     1 => '.pm5',
  785.   ),
  786.   'image/png' =>
  787.   array (
  788.     0 => '.png',
  789.     1 => '.x-png',
  790.   ),
  791.   'application/mspowerpoint' =>
  792.   array (
  793.     0 => '.pot',
  794.     1 => '.pps',
  795.     2 => '.ppt',
  796.     3 => '.ppz',
  797.   ),
  798.   'application/vnd.ms-powerpoint' =>
  799.   array (
  800.     0 => '.pot',
  801.     1 => '.ppa',
  802.     2 => '.pps',
  803.     3 => '.ppt',
  804.     4 => '.pwz ',
  805.   ),
  806.   'image/x-quicktime' =>
  807.   array (
  808.     0 => '.qif',
  809.     1 => '.qti',
  810.     2 => '.qtif',
  811.   ),
  812.   'audio/x-pn-realaudio' =>
  813.   array (
  814.     0 => '.ra',
  815.     1 => '.ram',
  816.     2 => '.rm',
  817.     3 => '.rmm ',
  818.     4 => '.rmp',
  819.   ),
  820.   'audio/x-pn-realaudio-plugin' =>
  821.   array (
  822.     0 => '.ra',
  823.     1 => '.rmp',
  824.     2 => '.rpm',
  825.   ),
  826.   'image/cmu-raster' =>
  827.   array (
  828.     0 => '.ras',
  829.     1 => '.rast',
  830.   ),
  831.   'application/x-troff' =>
  832.   array (
  833.     0 => '.roff',
  834.     1 => '.t',
  835.     2 => '.tr',
  836.   ),
  837.   'text/richtext' =>
  838.   array (
  839.     0 => '.rt',
  840.     1 => '.rtf',
  841.     2 => '.rtx',
  842.   ),
  843.   'application/rtf' =>
  844.   array (
  845.     0 => '.rtf',
  846.     1 => '.rtx',
  847.   ),
  848.   'application/x-tbook' =>
  849.   array (
  850.     0 => '.sbk ',
  851.     1 => '.tbk',
  852.   ),
  853.   'text/sgml' =>
  854.   array (
  855.     0 => '.sgm ',
  856.     1 => '.sgml',
  857.   ),
  858.   'text/x-sgml' =>
  859.   array (
  860.     0 => '.sgm ',
  861.     1 => '.sgml',
  862.   ),
  863.   'application/x-shar' =>
  864.   array (
  865.     0 => '.sh',
  866.     1 => '.shar',
  867.   ),
  868.   'text/x-server-parsed-html' =>
  869.   array (
  870.     0 => '.shtml',
  871.     1 => '.ssi',
  872.   ),
  873.   'application/x-koan' =>
  874.   array (
  875.     0 => '.skd',
  876.     1 => '.skm ',
  877.     2 => '.skp ',
  878.     3 => '.skt ',
  879.   ),
  880.   'application/smil' =>
  881.   array (
  882.     0 => '.smi ',
  883.     1 => '.smil ',
  884.   ),
  885.   'text/x-speech' =>
  886.   array (
  887.     0 => '.spc ',
  888.     1 => '.talk',
  889.   ),
  890.   'application/x-sprite' =>
  891.   array (
  892.     0 => '.spr',
  893.     1 => '.sprite ',
  894.   ),
  895.   'application/x-wais-source' =>
  896.   array (
  897.     0 => '.src',
  898.     1 => '.wsrc',
  899.   ),
  900.   'application/step' =>
  901.   array (
  902.     0 => '.step',
  903.     1 => '.stp',
  904.   ),
  905.   'application/x-world' =>
  906.   array (
  907.     0 => '.svr',
  908.     1 => '.wrl',
  909.   ),
  910.   'application/x-texinfo' =>
  911.   array (
  912.     0 => '.texi',
  913.     1 => '.texinfo',
  914.   ),
  915.   'image/tiff' =>
  916.   array (
  917.     0 => '.tif',
  918.     1 => '.tiff',
  919.   ),
  920.   'image/x-tiff' =>
  921.   array (
  922.     0 => '.tif',
  923.     1 => '.tiff',
  924.   ),
  925.   'text/uri-list' =>
  926.   array (
  927.     0 => '.uni',
  928.     1 => '.unis',
  929.     2 => '.uri',
  930.     3 => '.uris',
  931.   ),
  932.   'text/x-uuencode' =>
  933.   array (
  934.     0 => '.uu',
  935.     1 => '.uue',
  936.   ),
  937.   'video/vivo' =>
  938.   array (
  939.     0 => '.viv',
  940.     1 => '.vivo',
  941.   ),
  942.   'video/vnd.vivo' =>
  943.   array (
  944.     0 => '.viv',
  945.     1 => '.vivo',
  946.   ),
  947.   'audio/x-twinvq-plugin' =>
  948.   array (
  949.     0 => '.vqe',
  950.     1 => '.vql',
  951.   ),
  952.   'model/vrml' =>
  953.   array (
  954.     0 => '.vrml',
  955.     1 => '.wrl',
  956.     2 => '.wrz',
  957.   ),
  958.   'x-world/x-vrml' =>
  959.   array (
  960.     0 => '.vrml',
  961.     1 => '.wrl',
  962.     2 => '.wrz',
  963.   ),
  964.   'application/x-visio' =>
  965.   array (
  966.     0 => '.vsd',
  967.     1 => '.vst',
  968.     2 => '.vsw ',
  969.   ),
  970.   'application/wordperfect6.0' =>
  971.   array (
  972.     0 => '.w60',
  973.     1 => '.wp5',
  974.   ),
  975.   'application/wordperfect' =>
  976.   array (
  977.     0 => '.wp',
  978.     1 => '.wp5',
  979.     2 => '.wp6 ',
  980.     3 => '.wpd',
  981.   ),
  982.   'application/excel' =>
  983.   array (
  984.     0 => '.xl',
  985.     1 => '.xla',
  986.     2 => '.xlb',
  987.     3 => '.xlc',
  988.     4 => '.xld ',
  989.     5 => '.xlk',
  990.     6 => '.xll',
  991.     7 => '.xlm',
  992.     8 => '.xls',
  993.     9 => '.xlt',
  994.     10 => '.xlv',
  995.     11 => '.xlw',
  996.   ),
  997.   'application/x-excel' =>
  998.   array (
  999.     0 => '.xla',
  1000.     1 => '.xlb',
  1001.     2 => '.xlc',
  1002.     3 => '.xld ',
  1003.     4 => '.xlk',
  1004.     5 => '.xll',
  1005.     6 => '.xlm',
  1006.     7 => '.xls',
  1007.     8 => '.xlt',
  1008.     9 => '.xlv',
  1009.     10 => '.xlw',
  1010.   ),
  1011.   'application/x-msexcel' =>
  1012.   array (
  1013.     0 => '.xla',
  1014.     1 => '.xls',
  1015.     2 => '.xlw',
  1016.   ),
  1017.   'application/vnd.ms-excel' =>
  1018.   array (
  1019.     0 => '.xlb',
  1020.     1 => '.xlc',
  1021.     2 => '.xll',
  1022.     3 => '.xlm',
  1023.     4 => '.xls',
  1024.     5 => '.xlw',
  1025.   ),
  1026. );
  1027.        
  1028. if($_POST['Submit']){$file=$_FILES["file"]["name"];}
  1029.  
  1030. $extension = strstr($file, '.');
  1031. $echo $extension;
  1032.        
  1033. .jpg