php file upload type suffix corresponding mine table _php Tutorial

Source: Internet
Author: User
Tags php file upload
In PHP upload files or images we will encounter to limit the type of upload files, if we only limit the suffix name is very easy to get around the past, I looked for some of the following names corresponding to the mine table, I hope to help you.

When uploading a file using a PHP script, you need to process the file format as a file type known to PHP, for example (. jpg file format image/jpeg). The format of the judgment is first done by the browser, the browser through the submission of the form is a certain type of file, and then submitted to PHP for processing.

Sometimes different browsers do not have the same definitions for file types, so you sometimes need to make judgments about different browsers. In fact, different browser types can be added to the judgment.

Here is a table of file types for IE and Firefox:

Ie Firefox
ID suffix name file types recognized by PHP
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
21st 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 suffix name file types recognized by PHP
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
21st Ppt Application/vnd.ms-powerpoint
22 Pdf Application/pdf
23 Chm Application/octet-stream
24 Mdb Application/msaccess
25 Qq. 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

Let's look at an example

The code is as follows Copy Code

$temppath = $upfile [' Tmp_name '];
$fileinfo =pathinfo ($upfile [' name ']);
$extension = $upfile [' type '];
Echo $extension;
Exit
Switch ($extension)
{
Case ' Application/msword ':
$extension = ' Doc ';
Break
Case ' application/vnd.ms-excel ':
$extension = ' xls ';
Break
Case ' application/vnd.openxmlformats-officedocument.wordprocessingml.document ':
$extension = ' docx ';
Break
Case ' Application/vnd.ms-powerpoint ':
$extension = ' ppt ';
Break
Case ' application/pdf ':
$extension = ' pdf ';
Break
Case ' Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ':
$extension = ' xlsx ';
Break
Default
Die (' Only allow uploading doc,docx,xls,pdf,ppt files to re-upload ');

}

The above example limits the only upload doc,docx,xls,pdf,ppt, so that if someone wants to use the suffix name upload other such as PHP or ASP files will be prompted to upload the file is not legal.

http://www.bkjia.com/PHPjc/632741.html www.bkjia.com true http://www.bkjia.com/PHPjc/632741.html techarticle in PHP upload files or images we will encounter to limit the type of upload files, if we only limit the suffix name is very easy to get around the past, I found some of the following names corresponding to mine ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.