Checking If a File or Directory Exists in PHP


Use file_exists() to check if a file or directory exists.

Source Code

$filename = "test.txt";
if (file_exists($filename)) {
    echo "The file $filename exists.";
} else {
    echo "The file $filename does not exist.";
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments