php判断常用上传文件类型,自动获取文件扩展名

星期四, 2012-03-29 | Author: Lee | php | 6,234 views

在用php进行文件上传的时候总要判断文件的扩展名名等进行是否允许操作,经测试记录比较常用的文件类型,
记录如下,如有不全,希望能补正修改,代码如下:

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
switch    ($_FILES['userupfile']['type'])   
   {     
   case    "image/jpeg":     
   $fileextname    =    "jpg";     
   break;  
    case    "image/pjpeg":     
   $fileextname    =    "jpg";     
   break;    
   case    "image/gif":     
   $fileextname    =    "gif";     
   break;     
   case    "image/png":     
   $fileextname    =    "png";     
   break; 
   case    "image/x-png":     
   $fileextname    =    "png";     
   break; 
    case    "image/bmp":     
   $fileextname    =    "bmp";     
   break;    
   case    "application/x-shockwave-flash":     
   $fileextname    =    "swf";     
   break;     
   case    "text/plain":     
   $fileextname    =    "txt";     
   break;     
   case    "application/msword":     
   $fileextname    =    "doc";     
   break;     
   case    "application/x-zip-compressed":     
   $fileextname    =    "zip";     
   break; 
   case    "application/vnd.ms-excel":     
   $fileextname    =    "xls";     
   break; 
   case    "application/vnd.openxmlformats-officedocument.wordprocessingml.document":     
   $fileextname    =    "docx";     
   break; 
   case    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":     
   $fileextname    =    "xlsx";     
   break; 
   case    "application/pdf":     
   $fileextname    =    "pdf";     
   break;   
 
   }

Tags: , , ,

文章作者: Lee

本文地址: https://www.pomelolee.com/924.html

除非注明,Pomelo Lee文章均为原创,转载请以链接形式标明本文地址

No comments yet.

Leave a comment

Search

文章分类

Links

Meta