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

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

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


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,824
PHP 15-11-23 조회 3,033
PHP 15-11-21 조회 2,966
PHP 15-11-21 조회 3,003
PHP 15-11-21 조회 2,352
PHP 15-11-20 조회 2,729
PHP 15-11-20 조회 2,571
PHP 15-11-20 조회 3,058
PHP 15-11-18 조회 3,173
PHP 15-11-18 조회 3,458
PHP 15-11-18 조회 3,126
PHP 15-11-17 조회 1.3만
PHP 15-11-17 조회 3,147
PHP 15-11-17 조회 2,723
PHP 15-11-16 조회 2,533
PHP 15-11-16 조회 2,890
PHP 15-11-16 조회 4,007
PHP 15-11-15 조회 2,729
PHP 15-11-15 조회 2,159
PHP 15-11-15 조회 3,474
정규표현식 15-11-12 조회 8,067
웹서버 15-11-11 조회 2,981
jQuery 15-11-09 조회 3,717
jQuery 15-11-09 조회 3,278
PHP 15-11-09 조회 3,116
PHP 15-11-09 조회 2,603
PHP 15-11-09 조회 3,839
JavaScript 15-11-09 조회 4,291
PHP 15-11-06 조회 9,135
PHP 15-11-05 조회 2,735