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; } |
Search
相关文章
热门文章
最新文章
文章分类
- ajax (10)
- algorithm-learn (3)
- Android (6)
- as (3)
- computer (85)
- Database (30)
- disucz (4)
- enterprise (1)
- erlang (2)
- flash (5)
- golang (3)
- html5 (18)
- ios (4)
- JAVA-and-J2EE (186)
- linux (143)
- mac (10)
- movie-music (11)
- pagemaker (36)
- php (50)
- spring-boot (2)
- Synology群晖 (2)
- Uncategorized (6)
- unity (1)
- webgame (15)
- wordpress (33)
- work-other (2)
- 低代码 (1)
- 体味生活 (40)
- 前端 (21)
- 大数据 (8)
- 游戏开发 (9)
- 爱上海 (19)
- 读书 (4)
- 软件 (3)