一款实用php 正则文件扩展名代码
来源:程序员人生 发布时间:2014-05-10 20:37:20 阅读次数:3520次
- */
- function attachicon($type,$size='') {
- static $attachicons = array(
- 0 => 'common.gif',
- 1 => 'image.gif',
- 2 => 'binary.gif',
- 3 => 'rar.gif',
- 4 => 'msoffice.gif',
- 5 => 'text.gif',
- 6 => 'html.gif',
- 7 => 'real.gif',
- 8 => 'av.gif',
- 9 => 'flash.gif',
- 10 => 'pdf.gif',
- 11 => 'torrent.gif'
- );
-
- if(preg_match("/image|^(jpg|gif|png|bmp)/", $type)) {
- $typeid = 1;
- } elseif(preg_match("/bittorrent|^torrent/", $type)) {
- $typeid = 11;
- } elseif(preg_match("/pdf|^pdf/", $type)) {
- $typeid = 10;
- } elseif(preg_match("/flash|^(swf|fla|swi)/", $type)) {
- $typeid = 9;
- } elseif(preg_match("/audio|video|^(wav|mid|mp3|m3u|wma|asf|asx|vqf|mpg|mpeg|avi|wmv)/", $type)) {
- $typeid = 8;
- } elseif(preg_match("/real|^(rm|rv)/", $type)) {
- $typeid = 7;
- } elseif(preg_match("/htm|^(php|js|pl|cgi|asp教程)/", $type)) {
- $typeid = 6;
- } elseif(preg_match("/text|^(txt|rtf|wri|chm)/", $type)) {
- $typeid = 5;
- } elseif(preg_match("/word|powerpoint|^(doc|ppt)/", $type)) {
- $typeid = 4;
- } elseif(preg_match("/compressed|^(zip|arj|rar|arc|cab|lzh|lha|tar|gz)/", $type)) {
- $typeid = 3;
- } elseif(preg_match("/octet-stream|^(exe|com|bat|dll)/", $type)) {
- $typeid = 2;
- } else {
- $typeid = 0;
- }
- return $size.$attachicons[$typeid];
- }
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
------分隔线----------------------------
------分隔线----------------------------