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

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

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


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에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
MySQL 15-09-21 조회 3,456
15-08-06 조회 3,803
PHP 15-08-03 조회 3,749
PHP 15-07-12 조회 4,959
MySQL 15-07-02 조회 3,971
웹서버 15-06-16 조회 9,018
JavaScript 15-06-09 조회 4,982
jQuery 15-05-29 조회 5,848
기타 15-05-27 조회 8,188
기타 15-05-23 조회 4,370
기타 15-05-19 조회 5,271
기타 15-05-18 조회 1.4만
PHP 15-05-07 조회 9,374
웹서버 15-05-07 조회 4,704
JavaScript 15-05-06 조회 8,299
PHP 15-05-06 조회 9,314
PHP 15-05-06 조회 7,539
기타 15-04-13 조회 4,192
MySQL 11-01-14 조회 5,428
PHP 15-04-04 조회 5,267
PHP 15-04-04 조회 3,741
OS 15-04-03 조회 4,922
PHP 15-04-01 조회 7,233
JavaScript 15-03-28 조회 3,932
기타 15-03-20 조회 5,320
웹서버 15-03-02 조회 1만
PHP 15-02-10 조회 6,920
MySQL 15-02-09 조회 4,983
jQuery 15-02-02 조회 4,537
PHP 15-01-31 조회 9,115