천

파일이름의 확장자로 파일 종류를 확인하는 함수 입니다.

· 2015-11-18 (수) 06:11:01 · 3194

파일이름의 확장자로 파일 종류를 확인하는 함수입니다.
미디어스킨 또는 이미지 관련스킨에 유용할듯해서 올립니다.


function file_type($filename)
{
      $tmp = explode(".", $filename);
      $ext = trim($tmp[count($tmp)-1]);

      $type_image = "jpg|jpeg|gif|bmp|pcx|png";
      $type_compress = "zip|alz|gz|tar|z|rar|ace|bz|bz2";
      $type_text = "txt|text|rtf|2b";
      $type_html = "htm|html";
      $type_hwp = "hwp|h30";
      $type_exe = "exe";
      $type_font = "ttf";
      $type_movie = "avi|mpg|mpeg|mqv|asf|wmv|mov";
      $type_sound = "wav|mp3|mid|wma";

      if(preg_match("/($type_image)/i",$ext))
              $file_type = 'image';
      else if(preg_match("/($type_compress)/i",$ext))
              $file_type = 'compress';
      else if(preg_match("/($type_text)/i",$ext))
              $file_type = 'text';
      else if(preg_match("/($type_html)/i",$ext))
              $file_type = 'html';
      else if(preg_match("/($type_hwp)/i",$ext))
              $file_type = 'hwp';
      else if(preg_match("/($type_exe)/i",$ext))
              $file_type = 'exe';
      else if(preg_match("/($type_font)/i",$ext))
              $file_type = 'font';
      else if(preg_match("/($type_movie)/i",$ext))
              $file_type = 'movie';
      else if(preg_match("/($type_sound)/i",$ext))
              $file_type = 'sound';
      else
              $file_type = 'unknown';

      return $file_type;
}  

|
댓글을 작성하시려면 로그인이 필요합니다.

개발자팁

5,403건

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
PHP 15-11-23 조회 2,844
PHP 15-11-23 조회 3,058
PHP 15-11-21 조회 2,989
PHP 15-11-21 조회 3,028
PHP 15-11-21 조회 2,379
PHP 15-11-20 조회 2,752
PHP 15-11-20 조회 2,596
PHP 15-11-20 조회 3,081
PHP 15-11-18 조회 3,195
PHP 15-11-18 조회 3,478
PHP 15-11-18 조회 3,145
PHP 15-11-17 조회 1.3만
PHP 15-11-17 조회 3,166
PHP 15-11-17 조회 2,749
PHP 15-11-16 조회 2,555
PHP 15-11-16 조회 2,912
PHP 15-11-16 조회 4,032
PHP 15-11-15 조회 2,758
PHP 15-11-15 조회 2,179
PHP 15-11-15 조회 3,501
정규표현식 15-11-12 조회 8,087
웹서버 15-11-11 조회 3,004
jQuery 15-11-09 조회 3,739
jQuery 15-11-09 조회 3,299
PHP 15-11-09 조회 3,135
PHP 15-11-09 조회 2,639
PHP 15-11-09 조회 3,863
JavaScript 15-11-09 조회 4,328
PHP 15-11-06 조회 9,155
PHP 15-11-05 조회 2,762