首页 > 语言 > PHP > 正文

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

2024-09-04 11:47:20
字体:大 中 小
来源:转载
供稿:网友
  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]; 
  44. } 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表