Autor Tópico: Detectar o mime type de ficheiros  (Lida 2613 vezes)

Offline kingless

  • Newbie
  • *
  • Mensagens: 0
  • Karma: +0/-0
    • Ver Perfil
Detectar o mime type de ficheiros
« em: Fevereiro 03, 2007, 03:51:15 pm »
Acabei de criar um pequeno script para detectar o mime type de ficheiros aqui fica o código

Download:
http://www.kingless.net/download.php?filename=mime_type.php

Código: [Seleccione]

<?php

/////////////////////////////////////////

   //// File Mime types  ////

  ///  kingless - <blastelf>  ///

 // 03/02/2007  //

/////////////////////////////////////////



$file = "mime_type.php";



echo mime_type( $file );



function mime_type( $file ) {



$filetype = substr(strrchr( $file, \\'.\\' ), 1 );



$mimetypes = array(

"ez" => "application/andrew-inset",

"atom" => "application/atom+xml",

"hqx" => "application/mac-binhex40",

"cpt" => "application/mac-compactpro",

"doc" => "application/msword",

"lha" => "application/octet-stream",

"lzh" => "application/octet-stream",

"exe" => "application/octet-stream",

"so" => "application/octet-stream",

"dms" => "application/octet-stream",

"class" => "application/octet-stream",

"bin" => "application/octet-stream",

"dll" => "application/octet-stream",

"oda" => "application/oda",

"pdf" => "application/pdf",

"ps" => "application/postscript",

"eps" => "application/postscript",

"ai" => "application/postscript",

"smi" => "application/smil",

"smil" => "application/smil",

"mif" => "application/vnd.mif",

"xls" => "application/vnd.ms-excel",

"ppt" => "application/vnd.ms-powerpoint",

"wbxml" => "application/vnd.wap.wbxml",

"wmlc" => "application/vnd.wap.wmlc",

"wmlsc" => "application/vnd.wap.wmlscriptc",

"bcpio" => "application/x-bcpio",

"vcd" => "application/x-cdlink",

"pgn" => "application/x-chess-pgn",

"cpio" => "application/x-cpio",

"csh" => "application/x-csh",

"dir" => "application/x-director",

"dxr" => "application/x-director",

"dcr" => "application/x-director",

"dvi" => "application/x-dvi",

"spl" => "application/x-futuresplash",

"gtar" => "application/x-gtar",

"gz" => "application/x-gzip",

"hdf" => "application/x-hdf",

"php" => "application/x-httpd-php",

"phps" => "application/x-httpd-php-source",

"js" => "application/x-javascript",

"skm" => "application/x-koan",

"skt" => "application/x-koan",

"skp" => "application/x-koan",

"skd" => "application/x-koan",

"latex" => "application/x-latex",

"cdf" => "application/x-netcdf",

"nc" => "application/x-netcdf",

"sh" => "application/x-sh",

"shar" => "application/x-shar",

"swf" => "application/x-shockwave-flash",

"sit" => "application/x-stuffit",

"sv4cpio" => "application/x-sv4cpio",

"sv4crc" => "application/x-sv4crc",

"tar" => "application/x-tar",

"tcl" => "application/x-tcl",

"tex" => "application/x-tex",

"texi" => "application/x-texinfo",

"texinfo" => "application/x-texinfo",

"roff" => "application/x-troff",

"t" => "application/x-troff",

"tr" => "application/x-troff",

"man" => "application/x-troff-man",

"me" => "application/x-troff-me",

"ms" => "application/x-troff-ms",

"ustar" => "application/x-ustar",

"src" => "application/x-wais-source",

"xht" => "application/xhtml+xml",

"xhtml" => "application/xhtml+xml",

"zip" => "application/zip",

"au" => "audio/basic",

"snd" => "audio/basic",

"midi" => "audio/midi",

"kar" => "audio/midi",

"mid" => "audio/midi",

"mp3" => "audio/mpeg",

"mp2" => "audio/mpeg",

"mpga" => "audio/mpeg",

"aifc" => "audio/x-aiff",

"aif" => "audio/x-aiff",

"aiff" => "audio/x-aiff",

"m3u" => "audio/x-mpegurl",

"rm" => "audio/x-pn-realaudio",

"ram" => "audio/x-pn-realaudio",

"rpm" => "audio/x-pn-realaudio-plugin",

"ra" => "audio/x-realaudio",

"wav" => "audio/x-wav",

"pdb" => "chemical/x-pdb",

"xyz" => "chemical/x-xyz",

"bmp" => "image/bmp",

"gif" => "image/gif",

"ief" => "image/ief",

"jpe" => "image/jpeg",

"jpeg" => "image/jpeg",

"jpg" => "image/jpeg",

"png" => "image/png",

"tif" => "image/tiff",

"tiff" => "image/tiff",

"djvu" => "image/vnd.djvu",

"djv" => "image/vnd.djvu",

"wbmp" => "image/vnd.wap.wbmp",

"ras" => "image/x-cmu-raster",

"pnm" => "image/x-portable-anymap",

"pbm" => "image/x-portable-bitmap",

"pgm" => "image/x-portable-graymap",

"ppm" => "image/x-portable-pixmap",

"rgb" => "image/x-rgb",

"xbm" => "image/x-xbitmap",

"xpm" => "image/x-xpixmap",

"xwd" => "image/x-xwindowdump",

"igs" => "model/iges",

"iges" => "model/iges",

"mesh" => "model/mesh",

"silo" => "model/mesh",

"msh" => "model/mesh",

"vrml" => "model/vrml",

"wrl" => "model/vrml",

"css" => "text/css",

"htm" => "text/html",

"html" => "text/html",

"asc" => "text/plain",

"txt" => "text/plain",

"rtx" => "text/richtext",

"rtf" => "text/rtf",

"sgml" => "text/sgml",

"sgm" => "text/sgml",

"tsv" => "text/tab-separated-values",

"wml" => "text/vnd.wap.wml",

"wmls" => "text/vnd.wap.wmlscript",

"etx" => "text/x-setext",

"xml" => "text/xml",

"xsl" => "text/xml",

"mpe" => "video/mpeg",

"mpeg" => "video/mpeg",

"mpg" => "video/mpeg",

"mov" => "video/quicktime",

"qt" => "video/quicktime",

"mxu" => "video/vnd.mpegurl",

"avi" => "video/x-msvideo",

"movie" => "video/x-sgi-movie",

"ice" => "x-conference/x-cooltalk"

);



return implode( \\'\\', array_keys( array_flip( $mimetypes ), $filetype ));

}

?>

Offline kingless

  • Newbie
  • *
  • Mensagens: 0
  • Karma: +0/-0
    • Ver Perfil
Detectar o mime type de ficheiros
« Responder #1 em: Fevereiro 03, 2007, 03:51:40 pm »
!!

Offline knife

  • Newbie
  • *
  • Mensagens: 0
  • Karma: +0/-0
    • Ver Perfil
    • http://helderpatinho.com
Detectar o mime type de ficheiros
« Responder #2 em: Fevereiro 19, 2007, 12:59:23 pm »
E isto serve para?

Offline kingless

  • Newbie
  • *
  • Mensagens: 0
  • Karma: +0/-0
    • Ver Perfil
Detectar o mime type de ficheiros
« Responder #3 em: Fevereiro 19, 2007, 02:56:01 pm »
mime type é um método utilizador pelos browsers para associarem ficheiros de um certo tipo a aplicações que trabalham com ficheiros daquele tipo

por exemplo:
Se fazes download de um ficheiro de texto (.txt) o browser vai associar o ficheiro ao bloco de notas.

http://en.wikipedia.org/wiki/MIME_type


O que este código faz é identificar o mime type de um certo ficheiro e retorna o tipo de mime type.

Offline Teotónio Ricardo

  • Administrator
  • Newbie
  • *****
  • Mensagens: 0
  • Karma: +0/-0
    • Ver Perfil
    • http://www.teotonio.pt
Detectar o mime type de ficheiros
« Responder #4 em: Fevereiro 25, 2007, 06:10:43 pm »
Bom code, isto parece que não mas às vezes faz falta...

 

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49