php获得上传文件扩展名

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

星期四, 三月 29th, 2012 | php | 没有评论

在用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: , , ,

Search

文章分类

Links

Meta