2012-01-23 12 views
8

PHP ha una funzione che restituisce un'estensione di file data un tipo di contenuto?PHP ha una funzione che restituisce l'estensione corretta del file, dato un tipo di contenuto valido?

Sto cercando qualcosa che funziona come:

<?php 
function getFileExtension($contentType) 
{ 
    if ($contentType === 'image/png') 
    { 
     return '.png'; 
    } 
    elseif ($contentType === 'image/jpg') 
    { 
     return '.jpg'; 
    } 
    elseif ($contentType === 'application/zip') 
    { 
     return '.zip'; 
    } 
    else 
    { 
     return FALSE; 
    } 
} 

L'obiettivo è quello di utilizzare una funzione di libreria che ha tutti i tipi di contenuto gestito. Sulla base del modello di cui sopra, Credo che avrei potuto rotolare il mio con qualcosa di simile:

<?php 
function getFileExtension($contentType) 
{ 
    $pieces = explode('/', $contentType); 
    return '.' . array_pop($pieces); 
} 

... ma che sembra janky. Qualcuno sa di una soluzione PHP già creata? LMK. Grazie!

+0

Come fai a sapere il tipo di contenuto? Stai servendo questi file? –

+0

Usa un'istruzione 'switch'. – Blender

+0

Leggete quanto segue: http://www.php.net/manual/en/book.fileinfo.php – Erik

risposta

20

Dato il numero limitato di tipi di file archiviati nel database della mia applicazione, la seguente classe/metodo era una soluzione accettabile.

<?php 
class AppUtil 
{ 
    public static function FileExt($contentType) 
    { 
     $map = array(
      'application/pdf' => '.pdf', 
      'application/zip' => '.zip', 
      'image/gif'   => '.gif', 
      'image/jpeg'  => '.jpg', 
      'image/png'   => '.png', 
      'text/css'   => '.css', 
      'text/html'   => '.html', 
      'text/javascript' => '.js', 
      'text/plain'  => '.txt', 
      'text/xml'   => '.xml', 
     ); 
     if (isset($map[$contentType])) 
     { 
      return $map[$contentType]; 
     } 

     // HACKISH CATCH ALL (WHICH IN MY CASE IS 
     // PREFERRED OVER THROWING AN EXCEPTION) 
     $pieces = explode('/', $contentType); 
     return '.' . array_pop($pieces); 
    } 
} 

echo AppUtil::FileExt('application/zip'); // prints '.zip' 

Prima di stabilirsi sulla soluzione di cui sopra, però, ho fatto qualche ricerca su Google (come suggerito da @whichdan) e trovato il seguente "estensione di tipo MIME" risorsa mappatura.

http://www.webmaster-toolkit.com/mime-types.shtml

Dopo aver fatto qualche analisi sui dati presentati nel URL sopra è diventato chiaro che non c'è una soluzione definitiva a questo problema (che è probabilmente il motivo per cui non c'è un "tipo di contenuto su file estensione "in PHP).

Per illustrare questo fatto a beneficio della comunità di Stack Overflow, ho analizzato i dati presentati nell'URL precedente e suddivido ciascun tipo di contenuto in una di due categorie: "DEFINITIVE" O "AMBIGUOUS". L'esecuzione di var_export su ciascuno dei miei array "post parse" risulta nel seguente codice PHP.

<?php 
// DEFINITIVE "CONTENT TYPE TO FILE EXTENSION" MAPPINGS 
$definitive = array (
    'application/x-authorware-bin' => '.aab', 
    'application/x-authorware-map' => '.aam', 
    'application/x-authorware-seg' => '.aas', 
    'text/vnd.abc' => '.abc', 
    'video/animaflex' => '.afl', 
    'application/x-aim' => '.aim', 
    'text/x-audiosoft-intra' => '.aip', 
    'application/x-navi-animation' => '.ani', 
    'application/x-nokia-9000-communicator-add-on-software' => '.aos', 
    'application/mime' => '.aps', 
    'application/arj' => '.arj', 
    'image/x-jg' => '.art', 
    'text/asp' => '.asp', 
    'application/x-mplayer2' => '.asx', 
    'video/x-ms-asf-plugin' => '.asx', 
    'audio/x-au' => '.au', 
    'application/x-troff-msvideo' => '.avi', 
    'video/avi' => '.avi', 
    'video/msvideo' => '.avi', 
    'video/x-msvideo' => '.avi', 
    'video/avs-video' => '.avs', 
    'application/x-bcpio' => '.bcpio', 
    'application/mac-binary' => '.bin', 
    'application/macbinary' => '.bin', 
    'application/x-binary' => '.bin', 
    'application/x-macbinary' => '.bin', 
    'image/x-windows-bmp' => '.bmp', 
    'application/x-bzip' => '.bz', 
    'application/vnd.ms-pki.seccat' => '.cat', 
    'application/clariscad' => '.ccad', 
    'application/x-cocoa' => '.cco', 
    'application/cdf' => '.cdf', 
    'application/x-cdf' => '.cdf', 
    'application/java' => '.class', 
    'application/java-byte-code' => '.class', 
    'application/x-java-class' => '.class', 
    'application/x-cpio' => '.cpio', 
    'application/mac-compactpro' => '.cpt', 
    'application/x-compactpro' => '.cpt', 
    'application/x-cpt' => '.cpt', 
    'application/pkcs-crl' => '.crl', 
    'application/pkix-crl' => '.crl', 
    'application/x-x509-user-cert' => '.crt', 
    'application/x-csh' => '.csh', 
    'text/x-script.csh' => '.csh', 
    'application/x-pointplus' => '.css', 
    'text/css' => '.css', 
    'application/x-deepv' => '.deepv', 
    'video/dl' => '.dl', 
    'video/x-dl' => '.dl', 
    'application/commonground' => '.dp', 
    'application/drafting' => '.drw', 
    'application/x-dvi' => '.dvi', 
    'drawing/x-dwf (old)' => '.dwf', 
    'model/vnd.dwf' => '.dwf', 
    'application/acad' => '.dwg', 
    'application/dxf' => '.dxf', 
    'text/x-script.elisp' => '.el', 
    'application/x-bytecode.elisp (compiled elisp)' => '.elc', 
    'application/x-elc' => '.elc', 
    'application/x-esrehber' => '.es', 
    'text/x-setext' => '.etx', 
    'application/envoy' => '.evy', 
    'application/vnd.fdf' => '.fdf', 
    'application/fractals' => '.fif', 
    'image/fif' => '.fif', 
    'video/fli' => '.fli', 
    'video/x-fli' => '.fli', 
    'text/vnd.fmi.flexstor' => '.flx', 
    'video/x-atomic3d-feature' => '.fmf', 
    'image/vnd.fpx' => '.fpx', 
    'image/vnd.net-fpx' => '.fpx', 
    'application/freeloader' => '.frl', 
    'image/g3fax' => '.g3', 
    'image/gif' => '.gif', 
    'video/gl' => '.gl', 
    'video/x-gl' => '.gl', 
    'application/x-gsp' => '.gsp', 
    'application/x-gss' => '.gss', 
    'application/x-gtar' => '.gtar', 
    'multipart/x-gzip' => '.gzip', 
    'application/x-hdf' => '.hdf', 
    'text/x-script' => '.hlb', 
    'application/hlp' => '.hlp', 
    'application/x-winhelp' => '.hlp', 
    'application/binhex' => '.hqx', 
    'application/binhex4' => '.hqx', 
    'application/mac-binhex' => '.hqx', 
    'application/mac-binhex40' => '.hqx', 
    'application/x-binhex40' => '.hqx', 
    'application/x-mac-binhex40' => '.hqx', 
    'application/hta' => '.hta', 
    'text/x-component' => '.htc', 
    'text/webviewhtml' => '.htt', 
    'x-conference/x-cooltalk' => '.ice ', 
    'image/x-icon' => '.ico', 
    'application/x-ima' => '.ima', 
    'application/x-httpd-imap' => '.imap', 
    'application/inf' => '.inf ', 
    'application/x-internett-signup' => '.ins', 
    'application/x-ip2' => '.ip ', 
    'video/x-isvideo' => '.isu', 
    'audio/it' => '.it', 
    'application/x-inventor' => '.iv', 
    'i-world/i-vrml' => '.ivr', 
    'application/x-livescreen' => '.ivy', 
    'audio/x-jam' => '.jam ', 
    'application/x-java-commerce' => '.jcm ', 
    'image/x-jps' => '.jps', 
    'application/x-javascript' => '.js ', 
    'image/jutvision' => '.jut', 
    'music/x-karaoke' => '.kar', 
    'application/x-ksh' => '.ksh', 
    'text/x-script.ksh' => '.ksh', 
    'audio/x-liveaudio' => '.lam', 
    'application/lha' => '.lha', 
    'application/x-lha' => '.lha', 
    'application/x-lisp' => '.lsp ', 
    'text/x-script.lisp' => '.lsp ', 
    'text/x-la-asf' => '.lsx', 
    'application/x-lzh' => '.lzh', 
    'application/lzx' => '.lzx', 
    'application/x-lzx' => '.lzx', 
    'text/x-m' => '.m', 
    'audio/x-mpequrl' => '.m3u ', 
    'application/x-troff-man' => '.man', 
    'application/x-navimap' => '.map', 
    'application/mbedlet' => '.mbd', 
    'application/x-magic-cap-package-1.0' => '.mc$', 
    'application/mcad' => '.mcd', 
    'application/x-mathcad' => '.mcd', 
    'image/vasa' => '.mcf', 
    'text/mcf' => '.mcf', 
    'application/netmc' => '.mcp', 
    'application/x-troff-me' => '.me ', 
    'application/x-frame' => '.mif', 
    'application/x-mif' => '.mif', 
    'www/mime' => '.mime ', 
    'audio/x-vnd.audioexplosion.mjuicemediafile' => '.mjf', 
    'video/x-motion-jpeg' => '.mjpg ', 
    'application/x-meme' => '.mm', 
    'audio/mod' => '.mod', 
    'audio/x-mod' => '.mod', 
    'audio/x-mpeg' => '.mp2', 
    'video/x-mpeq2a' => '.mp2', 
    'audio/mpeg3' => '.mp3', 
    'audio/x-mpeg-3' => '.mp3', 
    'application/vnd.ms-project' => '.mpp', 
    'application/marc' => '.mrc', 
    'application/x-troff-ms' => '.ms', 
    'application/x-vnd.audioexplosion.mzz' => '.mzz', 
    'application/vnd.nokia.configuration-message' => '.ncm', 
    'application/x-mix-transfer' => '.nix', 
    'application/x-conference' => '.nsc', 
    'application/x-navidoc' => '.nvd', 
    'application/oda' => '.oda', 
    'application/x-omc' => '.omc', 
    'application/x-omcdatamaker' => '.omcd', 
    'application/x-omcregerator' => '.omcr', 
    'text/x-pascal' => '.p', 
    'application/pkcs10' => '.p10', 
    'application/x-pkcs10' => '.p10', 
    'application/pkcs-12' => '.p12', 
    'application/x-pkcs12' => '.p12', 
    'application/x-pkcs7-signature' => '.p7a', 
    'application/x-pkcs7-certreqresp' => '.p7r', 
    'application/pkcs7-signature' => '.p7s', 
    'text/pascal' => '.pas', 
    'image/x-portable-bitmap' => '.pbm ', 
    'application/vnd.hp-pcl' => '.pcl', 
    'application/x-pcl' => '.pcl', 
    'image/x-pict' => '.pct', 
    'image/x-pcx' => '.pcx', 
    'application/pdf' => '.pdf', 
    'audio/make.my.funk' => '.pfunk', 
    'image/x-portable-graymap' => '.pgm', 
    'image/x-portable-greymap' => '.pgm', 
    'application/x-newton-compatible-pkg' => '.pkg', 
    'application/vnd.ms-pki.pko' => '.pko', 
    'text/x-script.perl' => '.pl', 
    'application/x-pixclscript' => '.plx', 
    'text/x-script.perl-module' => '.pm', 
    'application/x-portable-anymap' => '.pnm', 
    'image/x-portable-anymap' => '.pnm', 
    'model/x-pov' => '.pov', 
    'image/x-portable-pixmap' => '.ppm', 
    'application/powerpoint' => '.ppt', 
    'application/x-mspowerpoint' => '.ppt', 
    'application/x-freelance' => '.pre', 
    'paleovu/x-pv' => '.pvu', 
    'text/x-script.phyton' => '.py ', 
    'applicaiton/x-bytecode.python' => '.pyc ', 
    'audio/vnd.qcelp' => '.qcp ', 
    'video/x-qtc' => '.qtc', 
    'audio/x-realaudio' => '.ra', 
    'application/x-cmu-raster' => '.ras', 
    'image/x-cmu-raster' => '.ras', 
    'text/x-script.rexx' => '.rexx ', 
    'image/vnd.rn-realflash' => '.rf', 
    'image/x-rgb' => '.rgb ', 
    'application/vnd.rn-realmedia' => '.rm', 
    'audio/mid' => '.rmi', 
    'application/ringing-tones' => '.rng', 
    'application/vnd.nokia.ringing-tone' => '.rng', 
    'application/vnd.rn-realplayer' => '.rnx ', 
    'image/vnd.rn-realpix' => '.rp ', 
    'text/vnd.rn-realtext' => '.rt', 
    'application/x-rtf' => '.rtf', 
    'video/vnd.rn-realvideo' => '.rv', 
    'audio/s3m' => '.s3m ', 
    'application/x-lotusscreencam' => '.scm', 
    'text/x-script.guile' => '.scm', 
    'text/x-script.scheme' => '.scm', 
    'video/x-scm' => '.scm', 
    'application/sdp' => '.sdp ', 
    'application/x-sdp' => '.sdp ', 
    'application/sounder' => '.sdr', 
    'application/sea' => '.sea', 
    'application/x-sea' => '.sea', 
    'application/set' => '.set', 
    'application/x-sh' => '.sh', 
    'text/x-script.sh' => '.sh', 
    'audio/x-psid' => '.sid', 
    'application/x-sit' => '.sit', 
    'application/x-stuffit' => '.sit', 
    'application/x-seelogo' => '.sl ', 
    'audio/x-adpcm' => '.snd', 
    'application/solids' => '.sol', 
    'application/x-pkcs7-certificates' => '.spc ', 
    'application/futuresplash' => '.spl', 
    'application/streamingmedia' => '.ssm ', 
    'application/vnd.ms-pki.certstore' => '.sst', 
    'application/sla' => '.stl', 
    'application/vnd.ms-pki.stl' => '.stl', 
    'application/x-navistyle' => '.stl', 
    'application/x-sv4cpio' => '.sv4cpio', 
    'application/x-sv4crc' => '.sv4crc', 
    'x-world/x-svr' => '.svr', 
    'application/x-shockwave-flash' => '.swf', 
    'application/x-tar' => '.tar', 
    'application/toolbook' => '.tbk', 
    'application/x-tcl' => '.tcl', 
    'text/x-script.tcl' => '.tcl', 
    'text/x-script.tcsh' => '.tcsh', 
    'application/x-tex' => '.tex', 
    'application/plain' => '.text', 
    'application/gnutar' => '.tgz', 
    'audio/tsp-audio' => '.tsi', 
    'application/dsptype' => '.tsp', 
    'audio/tsplayer' => '.tsp', 
    'text/tab-separated-values' => '.tsv', 
    'text/x-uil' => '.uil', 
    'application/i-deas' => '.unv', 
    'application/x-ustar' => '.ustar', 
    'multipart/x-ustar' => '.ustar', 
    'application/x-cdlink' => '.vcd', 
    'text/x-vcalendar' => '.vcs', 
    'application/vda' => '.vda', 
    'video/vdo' => '.vdo', 
    'application/groupwise' => '.vew ', 
    'application/vocaltec-media-desc' => '.vmd ', 
    'application/vocaltec-media-file' => '.vmf', 
    'audio/voc' => '.voc', 
    'audio/x-voc' => '.voc', 
    'video/vosaic' => '.vos', 
    'audio/voxware' => '.vox', 
    'audio/x-twinvq' => '.vqf', 
    'application/x-vrml' => '.vrml', 
    'x-world/x-vrt' => '.vrt', 
    'application/wordperfect6.1' => '.w61', 
    'audio/wav' => '.wav', 
    'audio/x-wav' => '.wav', 
    'application/x-qpro' => '.wb1', 
    'image/vnd.wap.wbmp' => '.wbmp', 
    'application/vnd.xara' => '.web', 
    'application/x-123' => '.wk1', 
    'windows/metafile' => '.wmf', 
    'text/vnd.wap.wml' => '.wml', 
    'application/vnd.wap.wmlc' => '.wmlc ', 
    'text/vnd.wap.wmlscript' => '.wmls', 
    'application/vnd.wap.wmlscriptc' => '.wmlsc ', 
    'application/x-wpwin' => '.wpd', 
    'application/x-lotus' => '.wq1', 
    'application/mswrite' => '.wri', 
    'application/x-wri' => '.wri', 
    'text/scriplet' => '.wsc', 
    'application/x-wintalk' => '.wtk ', 
    'image/x-xbitmap' => '.xbm', 
    'image/x-xbm' => '.xbm', 
    'image/xbm' => '.xbm', 
    'video/x-amt-demorun' => '.xdr', 
    'xgl/drawing' => '.xgz', 
    'image/vnd.xiff' => '.xif', 
    'audio/xm' => '.xm', 
    'application/xml' => '.xml', 
    'text/xml' => '.xml', 
    'xgl/movie' => '.xmz', 
    'application/x-vnd.ls-xpix' => '.xpix', 
    'image/xpm' => '.xpm', 
    'video/x-amt-showrun' => '.xsr', 
    'image/x-xwd' => '.xwd', 
    'image/x-xwindowdump' => '.xwd', 
    'application/x-compress' => '.z', 
    'application/x-zip-compressed' => '.zip', 
    'application/zip' => '.zip', 
    'multipart/x-zip' => '.zip', 
    'text/x-script.zsh' => '.zsh', 
); 

... e ...

<?php 
// AMBIGUOUS "CONTENT TYPE TO FILE EXTENSION" MAPPINGS 
$ambiguous = array (
    'x-world/x-3dmf' => 
    array (
    0 => '.3dm', 
    1 => '.3dmf', 
    2 => '.qd3 ', 
    3 => '.qd3d ', 
), 
    'application/octet-stream' => 
    array (
    0 => '.a', 
    1 => '.arc', 
    2 => '.arj', 
    3 => '.bin', 
    4 => '.com', 
    5 => '.dump', 
    6 => '.exe', 
    7 => '.lha', 
    8 => '.lhx', 
    9 => '.lzh', 
    10 => '.lzx', 
    11 => '.o', 
    12 => '.psd', 
    13 => '.saveme', 
    14 => '.uu', 
    15 => '.zoo', 
), 
    'text/html' => 
    array (
    0 => '.acgi', 
    1 => '.htm', 
    2 => '.html', 
    3 => '.htmls', 
    4 => '.htx ', 
    5 => '.shtml ', 
), 
    'application/postscript' => 
    array (
    0 => '.ai', 
    1 => '.eps', 
    2 => '.ps', 
), 
    'audio/aiff' => 
    array (
    0 => '.aif', 
    1 => '.aifc', 
    2 => '.aiff', 
), 
    'audio/x-aiff' => 
    array (
    0 => '.aif', 
    1 => '.aifc', 
    2 => '.aiff', 
), 
    'video/x-ms-asf' => 
    array (
    0 => '.asf', 
    1 => '.asx', 
), 
    'text/x-asm' => 
    array (
    0 => '.asm', 
    1 => '.s', 
), 
    'audio/basic' => 
    array (
    0 => '.au', 
    1 => '.snd', 
), 
    'image/bmp' => 
    array (
    0 => '.bm', 
    1 => '.bmp', 
), 
    'application/book' => 
    array (
    0 => '.boo', 
    1 => '.book', 
), 
    'application/x-bzip2' => 
    array (
    0 => '.boz', 
    1 => '.bz2', 
), 
    'application/x-bsh' => 
    array (
    0 => '.bsh', 
    1 => '.sh', 
    2 => '.shar', 
), 
    'text/plain' => 
    array (
    0 => '.c', 
    1 => '.c++', 
    2 => '.cc', 
    3 => '.com', 
    4 => '.conf', 
    5 => '.cxx', 
    6 => '.def', 
    7 => '.f', 
    8 => '.f90', 
    9 => '.for', 
    10 => '.g', 
    11 => '.h', 
    12 => '.hh', 
    13 => '.idc', 
    14 => '.jav', 
    15 => '.java', 
    16 => '.list', 
    17 => '.log ', 
    18 => '.lst ', 
    19 => '.m', 
    20 => '.mar', 
    21 => '.pl', 
    22 => '.sdml', 
    23 => '.text', 
    24 => '.txt', 
), 
    'text/x-c' => 
    array (
    0 => '.c', 
    1 => '.cc', 
    2 => '.cpp', 
), 
    'application/x-netcdf' => 
    array (
    0 => '.cdf', 
    1 => '.nc', 
), 
    'application/pkix-cert' => 
    array (
    0 => '.cer', 
    1 => '.crt', 
), 
    'application/x-x509-ca-cert' => 
    array (
    0 => '.cer', 
    1 => '.crt', 
    2 => '.der', 
), 
    'application/x-chat' => 
    array (
    0 => '.cha', 
    1 => '.chat', 
), 
    'application/x-director' => 
    array (
    0 => '.dcr', 
    1 => '.dir', 
    2 => '.dxr', 
), 
    'video/x-dv' => 
    array (
    0 => '.dif', 
    1 => '.dv', 
), 
    'application/msword' => 
    array (
    0 => '.doc', 
    1 => '.dot', 
    2 => '.w6w', 
    3 => '.wiz', 
    4 => '.word ', 
), 
    'image/vnd.dwg' => 
    array (
    0 => '.dwg', 
    1 => '.dxf', 
    2 => '.svf', 
), 
    'image/x-dwg' => 
    array (
    0 => '.dwg', 
    1 => '.dxf', 
    2 => '.svf', 
), 
    'application/x-envoy' => 
    array (
    0 => '.env', 
    1 => '.evy', 
), 
    'text/x-fortran' => 
    array (
    0 => '.f', 
    1 => '.f77', 
    2 => '.f90', 
    3 => '.for', 
), 
    'image/florian' => 
    array (
    0 => '.flo', 
    1 => '.turbot', 
), 
    'audio/make' => 
    array (
    0 => '.funk', 
    1 => '.my', 
    2 => '.pfunk', 
), 
    'audio/x-gsm' => 
    array (
    0 => '.gsd', 
    1 => '.gsm', 
), 
    'application/x-compressed' => 
    array (
    0 => '.gz', 
    1 => '.tgz', 
    2 => '.z', 
    3 => '.zip', 
), 
    'application/x-gzip' => 
    array (
    0 => '.gz', 
    1 => '.gzip', 
), 
    'text/x-h' => 
    array (
    0 => '.h', 
    1 => '.hh', 
), 
    'application/x-helpfile' => 
    array (
    0 => '.help', 
    1 => '.hlp', 
), 
    'application/vnd.hp-hpgl' => 
    array (
    0 => '.hgl', 
    1 => '.hpg', 
    2 => '.hpgl', 
), 
    'image/ief' => 
    array (
    0 => '.ief', 
    1 => '.iefs', 
), 
    'application/iges' => 
    array (
    0 => '.iges', 
    1 => '.igs', 
), 
    'model/iges' => 
    array (
    0 => '.iges ', 
    1 => '.igs', 
), 
    'text/x-java-source' => 
    array (
    0 => '.jav', 
    1 => '.java ', 
), 
    'image/jpeg' => 
    array (
    0 => '.jfif', 
    1 => '.jfif-tbnl', 
    2 => '.jpe', 
    3 => '.jpeg', 
    4 => '.jpg ', 
), 
    'image/pjpeg' => 
    array (
    0 => '.jfif', 
    1 => '.jpe', 
    2 => '.jpeg', 
    3 => '.jpg ', 
), 
    'audio/midi' => 
    array (
    0 => '.kar', 
    1 => '.mid', 
    2 => '.midi', 
), 
    'audio/nspaudio' => 
    array (
    0 => '.la ', 
    1 => '.lma', 
), 
    'audio/x-nspaudio' => 
    array (
    0 => '.la ', 
    1 => '.lma', 
), 
    'application/x-latex' => 
    array (
    0 => '.latex ', 
    1 => '.ltx', 
), 
    'video/mpeg' => 
    array (
    0 => '.m1v', 
    1 => '.m2v', 
    2 => '.mp2', 
    3 => '.mp3', 
    4 => '.mpa', 
    5 => '.mpe', 
    6 => '.mpeg', 
    7 => '.mpg', 
), 
    'audio/mpeg' => 
    array (
    0 => '.m2a', 
    1 => '.mp2', 
    2 => '.mpa', 
    3 => '.mpg', 
    4 => '.mpga', 
), 
    'message/rfc822' => 
    array (
    0 => '.mht', 
    1 => '.mhtml', 
    2 => '.mime ', 
), 
    'application/x-midi' => 
    array (
    0 => '.mid', 
    1 => '.midi', 
), 
    'audio/x-mid' => 
    array (
    0 => '.mid', 
    1 => '.midi', 
), 
    'audio/x-midi' => 
    array (
    0 => '.mid', 
    1 => '.midi', 
), 
    'music/crescendo' => 
    array (
    0 => '.mid', 
    1 => '.midi', 
), 
    'x-music/x-midi' => 
    array (
    0 => '.mid', 
    1 => '.midi', 
), 
    'application/base64' => 
    array (
    0 => '.mm', 
    1 => '.mme', 
), 
    'video/quicktime' => 
    array (
    0 => '.moov', 
    1 => '.mov', 
    2 => '.qt', 
), 
    'video/x-sgi-movie' => 
    array (
    0 => '.movie', 
    1 => '.mv', 
), 
    'video/x-mpeg' => 
    array (
    0 => '.mp2', 
    1 => '.mp3', 
), 
    'application/x-project' => 
    array (
    0 => '.mpc', 
    1 => '.mpt', 
    2 => '.mpv', 
    3 => '.mpx', 
), 
    'image/naplps' => 
    array (
    0 => '.nap', 
    1 => '.naplps', 
), 
    'image/x-niff' => 
    array (
    0 => '.nif', 
    1 => '.niff', 
), 
    'application/pkcs7-mime' => 
    array (
    0 => '.p7c', 
    1 => '.p7m', 
), 
    'application/x-pkcs7-mime' => 
    array (
    0 => '.p7c', 
    1 => '.p7m', 
), 
    'application/pro_eng' => 
    array (
    0 => '.part ', 
    1 => '.prt', 
), 
    'chemical/x-pdb' => 
    array (
    0 => '.pdb', 
    1 => '.xyz', 
), 
    'image/pict' => 
    array (
    0 => '.pic', 
    1 => '.pict', 
), 
    'image/x-xpixmap' => 
    array (
    0 => '.pm', 
    1 => '.xpm', 
), 
    'application/x-pagemaker' => 
    array (
    0 => '.pm4 ', 
    1 => '.pm5', 
), 
    'image/png' => 
    array (
    0 => '.png', 
    1 => '.x-png', 
), 
    'application/mspowerpoint' => 
    array (
    0 => '.pot', 
    1 => '.pps', 
    2 => '.ppt', 
    3 => '.ppz', 
), 
    'application/vnd.ms-powerpoint' => 
    array (
    0 => '.pot', 
    1 => '.ppa', 
    2 => '.pps', 
    3 => '.ppt', 
    4 => '.pwz ', 
), 
    'image/x-quicktime' => 
    array (
    0 => '.qif', 
    1 => '.qti', 
    2 => '.qtif', 
), 
    'audio/x-pn-realaudio' => 
    array (
    0 => '.ra', 
    1 => '.ram', 
    2 => '.rm', 
    3 => '.rmm ', 
    4 => '.rmp', 
), 
    'audio/x-pn-realaudio-plugin' => 
    array (
    0 => '.ra', 
    1 => '.rmp', 
    2 => '.rpm', 
), 
    'image/cmu-raster' => 
    array (
    0 => '.ras', 
    1 => '.rast', 
), 
    'application/x-troff' => 
    array (
    0 => '.roff', 
    1 => '.t', 
    2 => '.tr', 
), 
    'text/richtext' => 
    array (
    0 => '.rt', 
    1 => '.rtf', 
    2 => '.rtx', 
), 
    'application/rtf' => 
    array (
    0 => '.rtf', 
    1 => '.rtx', 
), 
    'application/x-tbook' => 
    array (
    0 => '.sbk ', 
    1 => '.tbk', 
), 
    'text/sgml' => 
    array (
    0 => '.sgm ', 
    1 => '.sgml', 
), 
    'text/x-sgml' => 
    array (
    0 => '.sgm ', 
    1 => '.sgml', 
), 
    'application/x-shar' => 
    array (
    0 => '.sh', 
    1 => '.shar', 
), 
    'text/x-server-parsed-html' => 
    array (
    0 => '.shtml', 
    1 => '.ssi', 
), 
    'application/x-koan' => 
    array (
    0 => '.skd', 
    1 => '.skm ', 
    2 => '.skp ', 
    3 => '.skt ', 
), 
    'application/smil' => 
    array (
    0 => '.smi ', 
    1 => '.smil ', 
), 
    'text/x-speech' => 
    array (
    0 => '.spc ', 
    1 => '.talk', 
), 
    'application/x-sprite' => 
    array (
    0 => '.spr', 
    1 => '.sprite ', 
), 
    'application/x-wais-source' => 
    array (
    0 => '.src', 
    1 => '.wsrc', 
), 
    'application/step' => 
    array (
    0 => '.step', 
    1 => '.stp', 
), 
    'application/x-world' => 
    array (
    0 => '.svr', 
    1 => '.wrl', 
), 
    'application/x-texinfo' => 
    array (
    0 => '.texi', 
    1 => '.texinfo', 
), 
    'image/tiff' => 
    array (
    0 => '.tif', 
    1 => '.tiff', 
), 
    'image/x-tiff' => 
    array (
    0 => '.tif', 
    1 => '.tiff', 
), 
    'text/uri-list' => 
    array (
    0 => '.uni', 
    1 => '.unis', 
    2 => '.uri', 
    3 => '.uris', 
), 
    'text/x-uuencode' => 
    array (
    0 => '.uu', 
    1 => '.uue', 
), 
    'video/vivo' => 
    array (
    0 => '.viv', 
    1 => '.vivo', 
), 
    'video/vnd.vivo' => 
    array (
    0 => '.viv', 
    1 => '.vivo', 
), 
    'audio/x-twinvq-plugin' => 
    array (
    0 => '.vqe', 
    1 => '.vql', 
), 
    'model/vrml' => 
    array (
    0 => '.vrml', 
    1 => '.wrl', 
    2 => '.wrz', 
), 
    'x-world/x-vrml' => 
    array (
    0 => '.vrml', 
    1 => '.wrl', 
    2 => '.wrz', 
), 
    'application/x-visio' => 
    array (
    0 => '.vsd', 
    1 => '.vst', 
    2 => '.vsw ', 
), 
    'application/wordperfect6.0' => 
    array (
    0 => '.w60', 
    1 => '.wp5', 
), 
    'application/wordperfect' => 
    array (
    0 => '.wp', 
    1 => '.wp5', 
    2 => '.wp6 ', 
    3 => '.wpd', 
), 
    'application/excel' => 
    array (
    0 => '.xl', 
    1 => '.xla', 
    2 => '.xlb', 
    3 => '.xlc', 
    4 => '.xld ', 
    5 => '.xlk', 
    6 => '.xll', 
    7 => '.xlm', 
    8 => '.xls', 
    9 => '.xlt', 
    10 => '.xlv', 
    11 => '.xlw', 
), 
    'application/x-excel' => 
    array (
    0 => '.xla', 
    1 => '.xlb', 
    2 => '.xlc', 
    3 => '.xld ', 
    4 => '.xlk', 
    5 => '.xll', 
    6 => '.xlm', 
    7 => '.xls', 
    8 => '.xlt', 
    9 => '.xlv', 
    10 => '.xlw', 
), 
    'application/x-msexcel' => 
    array (
    0 => '.xla', 
    1 => '.xls', 
    2 => '.xlw', 
), 
    'application/vnd.ms-excel' => 
    array (
    0 => '.xlb', 
    1 => '.xlc', 
    2 => '.xll', 
    3 => '.xlm', 
    4 => '.xls', 
    5 => '.xlw', 
), 
); 
+3

Non dovresti mettere il punto in ogni valore, finirai solo per mancarlo da qualche parte e aggiungerà rumore extra al tuo codice. Concatenare il punto con l'estensione nell'istruzione return o nel punto in cui si crea il nome del file. –