IT/php

php 강좌 php file_exists — 파일 또는 디렉토리가 있는지 여부를 확인합니다.

조원태 2016. 12. 7. 15:36
반응형

file_exists — 파일 또는 디렉토리가 있는지 여부를 확인합니다.


[설명]

bool file_exists ( string $filename )

파일 또는 디렉토리가 있는지 여부를 확인합니다.


[인수]

filename

파일 또는 디렉토리의 경로.


Windows에서는 // computername / share / filename 또는 \\ computername \ share \ filename을 사용하여 네트워크 공유의 파일을 검사합니다.


[반환값]

filename으로 지정된 파일이나 디렉토리가 있으면 TRUE를 반환하고 그렇지 않으면 TRUE를 반환합니다. 그렇지 않으면 FALSE.


Example #1 Testing whether a file exists

<?php

$filename = '/path/to/foo.txt';


if (file_exists($filename)) {

    echo "The file $filename exists";

} else {

    echo "The file $filename does not exist";

}

?>

반응형