천

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

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

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


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,834
PHP 15-11-23 조회 3,044
PHP 15-11-21 조회 2,980
PHP 15-11-21 조회 3,017
PHP 15-11-21 조회 2,368
PHP 15-11-20 조회 2,742
PHP 15-11-20 조회 2,582
PHP 15-11-20 조회 3,069
PHP 15-11-18 조회 3,181
PHP 15-11-18 조회 3,467
PHP 15-11-18 조회 3,135
PHP 15-11-17 조회 1.3만
PHP 15-11-17 조회 3,156
PHP 15-11-17 조회 2,734
PHP 15-11-16 조회 2,541
PHP 15-11-16 조회 2,901
PHP 15-11-16 조회 4,021
PHP 15-11-15 조회 2,747
PHP 15-11-15 조회 2,168
PHP 15-11-15 조회 3,489
정규표현식 15-11-12 조회 8,079
웹서버 15-11-11 조회 2,994
jQuery 15-11-09 조회 3,727
jQuery 15-11-09 조회 3,289
PHP 15-11-09 조회 3,124
PHP 15-11-09 조회 2,624
PHP 15-11-09 조회 3,851
JavaScript 15-11-09 조회 4,313
PHP 15-11-06 조회 9,144
PHP 15-11-05 조회 2,750