string filetype ( string $filename )
(PHP 4, PHP 5)

파일의 Type을 반환하는 함수로서 사용법은 다음과 같습니다.

<?php
 $fname = 'mail';
 // file_exists함수는 파일(또는 디렉토리)가 존재하는지 체크하는 함수
 if(file_exists($fname)){
     $type = filetype($fname);
 }
 echo $type; // 결과: dir

 $fname = 'test.php';
 if(file_exists($fname)){
     $type = filetype($fname);
 }
 echo $type; // 결과: file
 ?>

파일의 타입, 즉 파일의 유형에 따라 다음 표의 값을 반환합니다.

반환값 설 명
fifo 네임드 파이프
char 캐릭터 디바이스
dir 디렉토리
block 블록 디바이스
link 심벌릭 링크
file 일반 파일
unknown 알 수 없는 파일

<?php
 $type = filetype('./mail');
 if($type === 'dir')  {
    echo "mail은 디렉토리입니다.";
 }

 $type = filetype('./slink');
 if($type === 'link')  {
    echo "slink는 심볼릭 링크파일입니다.";
 }
 ?>

0 댓글