The role of mime: Enable the client software to distinguish different types of data. For example, a Web browser uses the MIME type to determine whether a file is a GIF image or a printable postscript file.
The Web server uses mime to describe the type of data sent. The Web client uses mime to describe the type of data to be received.
The tomcat installation directory/CONF/Web. xml defines a large number of MIME types. You can also take a look.
I recently used a form to upload files. To verify the file type on the server, I only allowed to upload GIF, JPG, and zip files. We have two methods,
First, check the file extension. Second, check the MIME type of the file.
The method to check the file extension is simple and quick, but you can bypass the check and upload by renaming a. jsp to a.jpg.
The method for checking the MIME type of a file is a little different in IE7 and Firefox (see the table below), and the upload performance of different browsers is inconsistent. The MIME types of zip and exe files in Firefox are the same as application/octet-stream.
Therefore, I decided to use the two methods in combination, first check the extension, and then check the mime. Unqualified files are not allowed to be uploaded.
The following table lists the MIME types obtained when the server (tomcat5.5) receives files uploaded by different browsers.
|
Upload with IE7 |
Upload with firefox3.0 |
GIF |
Image/GIF |
Image/GIF |
JPG |
Image/pjpeg |
Image/JPEG |
Zip |
Application/X-compressed |
Application/octet-stream |
JSP |
Text/html |
Text/html |
EXE |
Application/octet-stream |
Application/octet-stream |
|
Upload with IE7 |
Upload with firefox3.0 |
GIF |
Image/GIF |
Image/GIF |
JPG |
Image/pjpeg |
Image/JPEG |
Zip |
Application/X-compressed |
Application/octet-stream |
JSP |
Text/html |
Text/html |
EXE |
Application/octet-stream |
Application/octet-stream |
Common MIME type example tables:
Serial number |
Content type |
File Extension |
Description |
1 |
Application/MSWord |
Doc |
Microsoft Word |
2 |
Application/octet-stream Bin |
Dms lha lzh EXE class |
Executable program |
3 |
Application/PDF |
PDF |
Adobe Acrobat |
4 |
Application/postscript |
AI EPS PS |
Postscript |
5 |
APPICATION/PowerPoint |
PPT |
Microsoft PowerPoint |
6 |
APPICATION/RTF |
RTF |
RTF Format |
7 |
APPICATION/X-compress |
Z |
UNIX compressed file |
8 |
Application/X-Gzip |
GZ |
Gzip |
9 |
Application/X-gtar |
Gtar |
Tar document (GNU format) |
10 |
Application/X-Shockwave-flash |
SWF |
Macromedia Flash |
11 |
Application/X-Tar |
Tar |
Tar (4.3bsd) |
12 |
Application/zip |
Zip |
WinZip |
13 |
Audio/basic |
AU SND |
Sun/next sound file |
14 |
Audio/MPEG |
MPEG MP2 |
MPEG sound file |
15 |
Audio/X-AIFF |
Mid MIDI RMF |
MIDI format |
16 |
Audio/X-PN-RealAudio |
Ram Ra |
Real Audio voice |
17 |
Audio/X-PN-RealAudio-plugin |
Rpm |
Real Audio plugin |
18 |
Audio/X-WAV |
Wav |
Microsoft Windows sound |
19 |
Image/CGM |
CGM |
Computer Graphics Metafile |
20 |
Image/GIF |
GIF |
CompuServe GIF Image |
21 |
Image/JPEG |
Jpeg jpg jpe |
JPEG Image |
22 |
Image/PNG |
PNG |
PNG Image |
|
Upload with IE7 |
Upload with firefox3.0 |
GIF |
Image/GIF |
Image/GIF |
JPG |
Image/pjpeg |
Image/JPEG |
Zip |
Application/X-compressed |
Application/octet-stream |
JSP |
Text/html |
Text/html |
EXE |
Application/octet-stream |
Application/octet-stream |
Serial number |
Content type |
File Extension |
Description |
1 |
Application/MSWord |
Doc |
Microsoft Word |
2 |
Application/octet-stream Bin |
Dms lha lzh EXE class |
Executable program |
3 |
Application/PDF |
PDF |
Adobe Acrobat |
4 |
Application/postscript |
AI EPS PS |
Postscript |
5 |
APPICATION/PowerPoint |
PPT |
Microsoft PowerPoint |
6 |
APPICATION/RTF |
RTF |
RTF Format |
7 |
APPICATION/X-compress |
Z |
UNIX compressed file |
8 |
Application/X-Gzip |
GZ |
Gzip |
9 |
Application/X-gtar |
Gtar |
Tar document (GNU format) |
10 |
Application/X-Shockwave-flash |
SWF |
Macromedia Flash |
11 |
Application/X-Tar |
Tar |
Tar (4.3bsd) |
12 |
Application/zip |
Zip |
WinZip |
13 |
Audio/basic |
AU SND |
Sun/next sound file |
14 |
Audio/MPEG |
MPEG MP2 |
MPEG sound file |
15 |
Audio/X-AIFF |
Mid MIDI RMF |
MIDI format |
16 |
Audio/X-PN-RealAudio |
Ram Ra |
Real Audio voice |
17 |
Audio/X-PN-RealAudio-plugin |
Rpm |
Real Audio plugin |
18 |
Audio/X-WAV |
Wav |
Microsoft Windows sound |
19 |
Image/CGM |
CGM |
Computer Graphics Metafile |
20 |
Image/GIF |
GIF |
CompuServe GIF Image |
21 |
Image/JPEG |
Jpeg jpg jpe |
JPEG Image |
22 |
Image/PNG |
PNG |
PNG Image |