网上有很多PHP文件上传的类,文件上传处理是PHP的一个特色(至少手册上是将此作为PHP特点来展示的,个人认为PHP在数组方面的优异功能更有特色),学PHP的人都知道文件上传怎么做,但很多人在编程中却可能忽视了一些细节问题,那就是文件的类型(MIME)。在表单将文件提交给PHP做处理之前,浏览器会先解析识别一边是什么类型的文件,之后进入PHP处理环节,PHP又会去识别解析此文件的原始类型(并不是说你改成什么后缀就是什么文件)。在这个过程中会有一些浏览器兼容,更准确来说是文件类型解析标识不一致的问题。这样在PHP处理Post过来的文件类型时就需要根据不同浏览器做更多的判断,最典型的就是IE和火狐下的区别。 PHP上传图片文件(gif,jpg,bmp,png,psd,ico) 史上最完全ooPHPer亲测版PHP文件上传之文件类型对应表,ie,火狐各一份。
ie |
火狐 |
id@H_403_14@
| 后缀名@H_403_14@
| PHP识别出的文件类型@H_403_14@ |
0 |
gif |
image/gif |
1 |
jpg |
image/jpeg |
2 |
png |
image/png |
3 |
bmp |
image/bmp |
4 |
psd |
application/octet-stream |
5 |
ico |
image/x-icon |
6 |
rar |
application/octet-stream |
7 |
zip |
application/zip |
8 |
7z |
application/octet-stream |
9 |
exe |
application/octet-stream |
10 |
avi |
video/avi |
11 |
rmvb |
application/vnd.rn-realmedia-vbr |
12 |
3gp |
application/octet-stream |
13 |
flv |
application/octet-stream |
14 |
mp3 |
audio/mpeg |
15 |
wav |
audio/wav |
16 |
krc |
application/octet-stream |
17 |
lrc |
application/octet-stream |
18 |
txt |
text/plain |
19 |
doc |
application/msword |
20 |
xls |
application/vnd.ms-excel |
21 |
ppt |
application/vnd.ms-powerpoint |
22 |
pdf |
application/pdf |
23 |
chm |
application/octet-stream |
24 |
mdb |
application/msaccess |
25 |
sql |
application/octet-stream |
26 |
con |
application/octet-stream |
27 |
log |
text/plain |
28 |
dat |
application/octet-stream |
29 |
ini |
application/octet-stream |
30 |
PHP |
application/octet-stream |
31 |
html |
text/html |
32 |
htm |
text/html |
33 |
ttf |
application/octet-stream |
34 |
fon |
application/octet-stream |
35 |
js |
application/x-javascript |
36 |
xml |
text/xml |
37 |
dll |
application/octet-stream |
38 |
dll |
application/octet-stream | |
id@H_403_14@
| 后缀名@H_403_14@
| PHP识别出的文件类型@H_403_14@ |
0 |
gif |
image/gif |
1 |
jpg |
image/pjpeg |
2 |
png |
image/x-png |
3 |
bmp |
image/bmp |
4 |
psd |
application/octet-stream |
5 |
ico |
image/x-icon |
6 |
rar |
application/octet-stream |
7 |
zip |
application/x-zip-compressed |
8 |
7z |
application/octet-stream |
9 |
exe |
application/octet-stream |
10 |
avi |
video/avi |
11 |
rmvb |
application/vnd.rn-realmedia-vbr |
12 |
3gp |
application/octet-stream |
13 |
flv |
application/octet-stream |
14 |
mp3 |
audio/mpeg |
15 |
wav |
audio/wav |
16 |
krc |
application/octet-stream |
17 |
lrc |
application/octet-stream |
18 |
txt |
text/plain |
19 |
doc |
application/msword |
20 |
xls |
application/vnd.ms-excel |
21 |
ppt |
application/vnd.ms-powerpoint |
22 |
pdf |
application/pdf |
23 |
chm |
application/octet-stream |
24 |
mdb |
application/msaccess |
25 |
sql |
text/plain |
26 |
con |
application/octet-stream |
27 |
log |
text/plain |
28 |
dat |
text/plain |
29 |
ini |
application/octet-stream |
30 |
PHP |
application/octet-stream |
31 |
html |
text/html |
32 |
htm |
text/html |
33 |
ttf |
application/octet-stream |
34 |
fon |
application/octet-stream |
35 |
js |
text/html |
36 |
xml |
text/xml |
37 |
dll |
application/octet-stream |
38 |
class |
application/java | |
* application/octet-stream //应用程序 @H_
404_668@323 text/h323 @H_
404_668@acx application/internet-property-stream @H_
404_668@ai application/postscript @H_
404_668@aif au
dio/x-aiff @H_
404_668@aifc au
dio/x-aiff @H_
404_668@aiff au
dio/x-aiff @H_
404_668@asf video/x-ms-asf @H_
404_668@asr video/x-ms-asf @H_
404_668@asx video/x-ms-asf @H_
404_668@au au
dio/basic @H_
404_668@avi video/x-msvideo @H_
404_668@axs application/olescript @H_
404_668@bas text/plain @H_
404_668@bcpio application/x-bcpio @H_
404_668@bin application/octet-stream @H_
404_668@bmp image/bmp @H_
404_668@c text/plain @H_
404_668@cat application/vnd.ms-pkiseccat @H_
404_668@cdf application/x-cdf @H_
404_668@cer application/x-x509-ca-cert @H_
404_668@class application/octet-stream @H_
404_668@clp application/x-msclip @H_
404_668@cmx image/x-cmx @H_
404_668@cod image/cis-cod @H_
404_668@cpio application/x-cpio @H_
404_668@crd application/x-mscardfile @H_
404_668@crl application/pkix-crl @H_
404_668@crt application/x-x509-ca-cert @H_
404_668@csh application/x-csh @H_
404_668@css text/css @H_
404_668@dcr application/x-director @H_
404_668@der application/x-x509-ca-cert @H_
404_668@dir application/x-director @H_
404_668@dll application/x-msdownload @H_
404_668@dms application/octet-stream @H_
404_668@doc application/msword @H_
404_668@dot application/msword @H_
404_668@dvi application/x-dvi @H_
404_668@dxr application/x-director @H_
404_668@eps application/postscript @H_
404_668@etx text/x-setext @H_
404_668@evy application/envoy @H_
404_668@exe application/octet-stream @H_
404_668@fif application/fractals @H_
404_668@flr x-world/x-vrml @H_
404_668@gif image/gif @H_
404_668@gtar application/x-gtar @H_
404_668@gz application/x-gzip @H_
404_668@h text/plain @H_
404_668@hdf application/x-hdf @H_
404_668@hlp application/winhlp @H_
404_668@hqx application/mac-binhex40 @H_
404_668@hta application/hta @H_
404_668@htc text/x-component @H_
404_668@htm text/html @H_
404_668@html text/html @H_
404_668@htt text/webviewhtml @H_
404_668@ico image/x-icon @H_
404_668@ief image/ief @H_
404_668@iii application/x-iphone @H_
404_668@ins application/x-internet-signup @H_
404_668@isp application/x-internet-signup @H_
404_668@jfif image/pipeg @H_
404_668@jpe image/jpeg @H_
404_668@jpeg image/jpeg @H_
404_668@jpg image/jpeg @H_
404_668@jpg image/pjpeg @H_
404_668@js application/x-javascript @H_
404_668@latex application/x-latex @H_
404_668@lha application/octet-stream @H_
404_668@lsf video/x-la-asf @H_
404_668@lsx video/x-la-asf @H_
404_668@lzh application/octet-stream @H_
404_668@m13 application/x-msmediaview @H_
404_668@m14 application/x-msmediaview @H_
404_668@m3u au
dio/x-mpegurl @H_
404_668@man application/x-troff-man @H_
404_668@mdb application/x-msaccess @H_
404_668@me application/x-troff-me @H_
404_668@mht message/rfc822 @H_
404_668@mhtml message/rfc822 @H_
404_668@mid au
dio/mid @H_
404_668@mny application/x-msmoney @H_
404_668@mov video/quicktime @H_
404_668@movie video/x-sgi-movie @H_
404_668@mp2 video/mpeg @H_
404_668@mp3 au
dio/mpeg @H_
404_668@mpa video/mpeg @H_
404_668@mpe video/mpeg @H_
404_668@mpeg video/mpeg @H_
404_668@mpg video/mpeg @H_
404_668@mpp application/vnd.ms-project @H_
404_668@mpv2 video/mpeg @H_
404_668@ms application/x-troff-ms @H_
404_668@mvb application/x-msmediaview @H_
404_668@nws message/rfc822 @H_
404_668@oda application/oda @H_
404_668@p10 application/pkcs10 @H_
404_668@p12 application/x-pkcs12 @H_
404_668@p7b application/x-pkcs7-certificates @H_
404_668@p7c application/x-pkcs7-mime @H_
404_668@p7m application/x-pkcs7-mime @H_
404_668@p7r application/x-pkcs7-certreqresp @H_
404_668@p7s application/x-pkcs7-signature @H_
404_668@pbm image/x-portable-bitmap @H_
404_668@pdf application/pdf @H_
404_668@pfx application/x-pkcs12 @H_
404_668@pgm image/x-portable-graymap @H_
404_668@pko application/ynd.ms-pkipko @H_
404_668@pma application/x-perfmon @H_
404_668@pmc application/x-perfmon @H_
404_668@pml application/x-perfmon @H_
404_668@pmr application/x-perfmon @H_
404_668@pmw application/x-perfmon @H_
404_668@png image/x-png @H_
404_668@pnm image/x-portable-anymap @H_
404_668@pot,application/vnd.ms-powerpoint @H_
404_668@ppm image/x-portable-pixmap @H_
404_668@pps application/vnd.ms-powerpoint @H_
404_668@ppt application/vnd.ms-powerpoint @H_
404_668@prf application/pics-rules @H_
404_668@ps application/postscript @H_
404_668@pub application/x-mspublisher @H_
404_668@qt video/quicktime @H_
404_668@ra au
dio/x-pn-realau
dio @H_
404_668@ram au
dio/x-pn-realau
dio @H_
404_668@ras image/x-cmu-raster @H_
404_668@rgb image/x-rgb @H_
404_668@rmi au
dio/mid @H_
404_668@roff application/x-troff @H_
404_668@rtf application/rtf @H_
404_668@rtx text/richtext @H_
404_668@scd application/x-msschedule @H_
404_668@sct text/scriptlet @H_
404_668@setpay application/set-payment-initiation @H_
404_668@setreg application/set-registration-initiation @H_
404_668@sh application/x-sh @H_
404_668@shar application/x-shar @H_
404_668@sit application/x-stuffit @H_
404_668@snd au
dio/basic @H_
404_668@spc application/x-pkcs7-certificates @H_
404_668@spl application/futuresplash @H_
404_668@src application/x-wais-source @H_
404_668@sst application/vnd.ms-pkicertstore @H_
404_668@stl application/vnd.ms-pkistl @H_
404_668@stm text/html @H_
404_668@sv4cpio application/x-sv4cpio @H_
404_668@sv4crc application/x-sv4crc @H_
404_668@t application/x-troff @H_
404_668@tar application/x-tar @H_
404_668@tcl application/x-tcl @H_
404_668@tex application/x-tex @H_
404_668@texi application/x-texinfo @H_
404_668@texinfo application/x-texinfo @H_
404_668@tgz application/x-compressed @H_
404_668@tif image/tiff @H_
404_668@tiff image/tiff @H_
404_668@tr application/x-troff @H_
404_668@trm application/x-msterminal @H_
404_668@tsv text/tab-separated-values @H_
404_668@txt text/plain @H_
404_668@uls text/iuls @H_
404_668@ustar application/x-ustar @H_
404_668@vcf text/x-vcard @H_
404_668@vrml x-world/x-vrml @H_
404_668@wav au
dio/x-wav @H_
404_668@wcm application/vnd.ms-works @H_
404_668@wdb application/vnd.ms-works @H_
404_668@wks application/vnd.ms-works @H_
404_668@wmf application/x-ms
Metafile @H_
404_668@wps application/vnd.ms-works @H_
404_668@wri application/x-mswrite @H_
404_668@wrl x-world/x-vrml @H_
404_668@wrz x-world/x-vrml @H_
404_668@xaf x-world/x-vrml @H_
404_668@xbm image/x-xbitmap @H_
404_668@xla application/vnd.ms-excel @H_
404_668@xlc application/vnd.ms-excel @H_
404_668@xlm application/vnd.ms-excel @H_
404_668@xls application/vnd.ms-excel @H_
404_668@xlt application/vnd.ms-excel @H_
404_668@xlw application/vnd.ms-excel @H_
404_668@xof x-world/x-vrml @H_
404_668@xpm image/x-xpixmap @H_
404_668@xwd image/x-xwindowdump @H_
404_668@z application/x-compress @H_
404_668@zip application/zip -firefox @H_
404_668@application/x-zip-compressed -IE @H_
404_668@
PHP上传压缩
文件(rar,7z,zip)
PHP上传可执行
文件(exe)
PHP上传视频
文件,音乐
文件,歌词
文件(avi,rmvb,3gp,flv,mp3,wav,krc,lrc)
PHP上传文本
文件和文档
文件(word->doc,excel->xls,
幻灯片->ppt,pdf,chm)
PHP上传数据库文件(access
文件,
sql文件,con
文件,日志
文件log,dat
文件)
PHP上传网页
文件,脚本
文件,字体
文件(ini,
PHP,html,htm,字体
文件:ttf,fon,js,xml)
PHP上传其他
文件(class类
文件,dll动态加载库
文件)