加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

一款实用php 正则文件扩展名代码

发布时间:2020-12-13 20:34:42 所属栏目:PHP教程 来源:网络整理
导读:*/ 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= t
  1. */ 
  2. function attachicon($type,$size='') { 
  3.  static $attachicons = array
  4.  0 => 'common.gif'
  5.  1 => 'image.gif'
  6.  2 => 'binary.gif'
  7.  3 => 'rar.gif'
  8.  4 => 'msoffice.gif'
  9.  5 => 'text.gif'
  10.  6 => 'html.gif'
  11.  7 => 'real.gif'
  12.  8 => 'av.gif'
  13.  9 => 'flash.gif'
  14.  10 => 'pdf.gif'
  15.  11 => 'torrent.gif' 
  16.  ); 
  17.  
  18.  if(preg_match("/image|^(jpg|gif|png|bmp)/"$type)) { 
  19.   $typeid = 1; 
  20.  } elseif(preg_match("/bittorrent|^torrent/"$type)) { 
  21.   $typeid = 11; 
  22.  } elseif(preg_match("/pdf|^pdf/"$type)) { 
  23.   $typeid = 10; 
  24.  } elseif(preg_match("/flash|^(swf|fla|swi)/"$type)) { 
  25.   $typeid = 9; 
  26.  } elseif(preg_match("/audio|video|^(wav|mid|mp3|m3u|wma|asf|asx|vqf|mpg|mpeg|avi|wmv)/"$type)) { 
  27.   $typeid = 8; 
  28.  } elseif(preg_match("/real|^(rm|rv)/"$type)) { 
  29.   $typeid = 7; 
  30.  } elseif(preg_match("/htm|^(php|js|pl|cgi|asp教程)/"$type)) { 
  31.   $typeid = 6; 
  32.  } elseif(preg_match("/text|^(txt|rtf|wri|chm)/"$type)) { 
  33.   $typeid = 5; 
  34.  } elseif(preg_match("/word|powerpoint|^(doc|ppt)/"$type)) { 
  35.   $typeid = 4; 
  36.  } elseif(preg_match("/compressed|^(zip|arj|rar|arc|cab|lzh|lha|tar|gz)/"$type)) { 
  37.   $typeid = 3; 
  38.  } elseif(preg_match("/octet-stream|^(exe|com|bat|dll)/"$type)) { 
  39.   $typeid = 2; 
  40.  } else { 
  41.   $typeid = 0; 
  42.  } 
  43.  return $size.$attachicons[$typeid]; 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读