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

· 10년 전 · 2860

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


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;
}  

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

개발자팁

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

+
분류 제목 글쓴이 날짜 조회
JavaScript 10년 전 조회 2,912
PHP 10년 전 조회 2,463
PHP 10년 전 조회 2,424
PHP 10년 전 조회 3,050
웹서버 10년 전 조회 3,315
PHP 10년 전 조회 7,196
PHP 10년 전 조회 2,479
PHP 10년 전 조회 2,700
PHP 10년 전 조회 2,628
PHP 10년 전 조회 2,696
PHP 10년 전 조회 2,064
PHP 10년 전 조회 2,432
PHP 10년 전 조회 2,246
PHP 10년 전 조회 2,731
PHP 10년 전 조회 2,861
PHP 10년 전 조회 3,158
PHP 10년 전 조회 2,794
PHP 10년 전 조회 1.2만
PHP 10년 전 조회 2,788
PHP 10년 전 조회 2,406
PHP 10년 전 조회 2,202
PHP 10년 전 조회 2,580
PHP 10년 전 조회 3,598
PHP 10년 전 조회 2,393
PHP 10년 전 조회 1,862
PHP 10년 전 조회 3,145
정규표현식 10년 전 조회 7,732
웹서버 10년 전 조회 2,657
jQuery 10년 전 조회 3,387
jQuery 10년 전 조회 2,929
🐛 버그신고