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

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

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


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,822
PHP 15-11-23 조회 3,032
PHP 15-11-21 조회 2,964
PHP 15-11-21 조회 3,003
PHP 15-11-21 조회 2,351
PHP 15-11-20 조회 2,728
PHP 15-11-20 조회 2,570
PHP 15-11-20 조회 3,056
PHP 15-11-18 조회 3,171
PHP 15-11-18 조회 3,457
PHP 15-11-18 조회 3,125
PHP 15-11-17 조회 1.3만
PHP 15-11-17 조회 3,147
PHP 15-11-17 조회 2,723
PHP 15-11-16 조회 2,531
PHP 15-11-16 조회 2,890
PHP 15-11-16 조회 4,005
PHP 15-11-15 조회 2,726
PHP 15-11-15 조회 2,157
PHP 15-11-15 조회 3,474
정규표현식 15-11-12 조회 8,066
웹서버 15-11-11 조회 2,977
jQuery 15-11-09 조회 3,716
jQuery 15-11-09 조회 3,276
PHP 15-11-09 조회 3,114
PHP 15-11-09 조회 2,601
PHP 15-11-09 조회 3,837
JavaScript 15-11-09 조회 4,291
PHP 15-11-06 조회 9,135
PHP 15-11-05 조회 2,735