您可以通过PHP上传哪些文件类型?

时间:2013-04-18 15:44:10

标签: php file-upload file-type

我正在尝试找到一个参考,显示“ TYPES ”的不同名称是什么$_FILES["file"]["type"] == "image/gif",但我正在寻找csv,ms excel,mac数字,ms word等。

我在php.net或google上找不到任何东西。无论如何,我很可能把它称为错误的东西。

我应该寻找的是什么?

3 个答案:

答案 0 :(得分:5)

这实际上是在PHP手册中解释的。

来自http://php.net/manual/en/features.file-upload.post-method.php(强调我的)

  

$_FILES['userfile']['type']:文件 mime类型,如果浏览器提供此信息。一个例子是“image / gif”。但是,在PHP方面没有检查这个mime类型,因此不会将其值视为理所当然。

因此,您要查找的术语是 MIME TYPE 。把它放到谷歌可能会让你最终到维基百科的https://en.wikipedia.org/wiki/Internet_media_type

  

Internet媒体类型[1]是Internet上文件格式的两部分标识符。标识符最初在RFC 2046中定义,用于通过SMTP发送的电子邮件,但它们的使用已扩展到其他协议,如HTTP,RTP和SIP。这些类型称为MIME类型,有时也称为内容类型,位于多个协议中的标头名称之后,其值是这种类型。

文章还说明了

  

IANA管理媒体类型的官方注册表

点击链接后会引导您

并包含您要查找的列表。请注意,查看该列表几乎没有意义,除非您想了解特定文件格式的官方mimetype是什么。

旁注:如果要验证/检测文件的mime类型,请检查我在

中提供的代码

答案 1 :(得分:4)

您正在寻找MIME类型。但请注意,您不应该信任$_FILES['...']['type']。相反,您应该自己分析文件内容以确保它们是正确的格式。

答案 2 :(得分:1)

在论坛上找到以下列表,似乎已经足够完整,可以在这里发布

'hqx'   =>  'application/mac-binhex40'
'cpt'   =>  'application/mac-compactpro'
'csv'   =>  'text/x-comma-separated-values', 'application/vnd.ms-excel'
'bin'   =>  'application/macbinary'
'dms'   =>  'application/octet-stream'
'lha'   =>  'application/octet-stream'
'lzh'   =>  'application/octet-stream'
'exe'   =>  'application/octet-stream'
'class' =>  'application/octet-stream'
'psd'   =>  'application/x-photoshop'
'so'    =>  'application/octet-stream'
'sea'   =>  'application/octet-stream'
'dll'   =>  'application/octet-stream'
'oda'   =>  'application/oda'
'pdf'   =>  'application/pdf', 'application/x-download'
'ai'    =>  'application/postscript'
'eps'   =>  'application/postscript'
'ps'    =>  'application/postscript'
'smi'   =>  'application/smil'
'smil'  =>  'application/smil'
'mif'   =>  'application/vnd.mif'
'xls'   =>  'application/excel', 'application/vnd.ms-excel'
'ppt'   =>  'application/powerpoint'
'wbxml' =>  'application/wbxml'
'wmlc'  =>  'application/wmlc'
'dcr'   =>  'application/x-director'
'dir'   =>  'application/x-director'
'dxr'   =>  'application/x-director'
'dvi'   =>  'application/x-dvi'
'gtar'  =>  'application/x-gtar'
'gz'    =>  'application/x-gzip'
'php'   =>  'application/x-httpd-php'
'php4'  =>  'application/x-httpd-php'
'php3'  =>  'application/x-httpd-php'
'phtml' =>  'application/x-httpd-php'
'phps'  =>  'application/x-httpd-php-source'
'js'    =>  'application/x-javascript'
'swf'   =>  'application/x-shockwave-flash'
'sit'   =>  'application/x-stuffit'
'tar'   =>  'application/x-tar'
'tgz'   =>  'application/x-tar'
'xhtml' =>  'application/xhtml+xml'
'xht'   =>  'application/xhtml+xml'
'zip'   => 'application/x-zip', 'application/zip', 'application/x-zip-compressed'
'mid'   =>  'audio/midi'
'midi'  =>  'audio/midi'
'mpga'  =>  'audio/mpeg'
'mp2'   =>  'audio/mpeg'
'mp3'   =>  'audio/mpeg'
'aif'   =>  'audio/x-aiff'
'aiff'  =>  'audio/x-aiff'
'aifc'  =>  'audio/x-aiff'
'ram'   =>  'audio/x-pn-realaudio'
'rm'    =>  'audio/x-pn-realaudio'
'rpm'   =>  'audio/x-pn-realaudio-plugin'
'ra'    =>  'audio/x-realaudio'
'rv'    =>  'video/vnd.rn-realvideo'
'wav'   =>  'audio/x-wav'
'bmp'   =>  'image/bmp'
'gif'   =>  'image/gif'
'jpeg'  =>  'image/jpeg', 'image/pjpeg'
'jpg'   =>  'image/jpeg', 'image/pjpeg'
'jpe'   =>  'image/jpeg', 'image/pjpeg'
'png'   =>  'image/png',  'image/x-png'
'tiff'  =>  'image/tiff'
'tif'   =>  'image/tiff'
'css'   =>  'text/css'
'html'  =>  'text/html'
'htm'   =>  'text/html'
'shtml' =>  'text/html'
'txt'   =>  'text/plain'
'text'  =>  'text/plain'
'log'   =>  'text/plain', 'text/x-log'
'rtx'   =>  'text/richtext'
'rtf'   =>  'text/rtf'
'xml'   =>  'text/xml'
'xsl'   =>  'text/xml'
'mpeg'  =>  'video/mpeg'
'mpg'   =>  'video/mpeg'
'mpe'   =>  'video/mpeg'
'qt'    =>  'video/quicktime'
'mov'   =>  'video/quicktime'
'avi'   =>  'video/x-msvideo'
'movie' =>  'video/x-sgi-movie'
'doc'   =>  'application/msword'
'word'  =>  'application/msword', 'application/octet-stream'
'xl'    =>  'application/excel'
'eml'   =>  'message/rfc822'