file_exists() in php

PHP provides some functions that enable you to access useful file information

For example, you can use file_exists() to discover whether a file exists before attempting to open it

file_exists( “myfile.txt” )

file_exists() returns true if the file at the specified path exists, or false otherwise

Example of file_exists

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

if (file_exists($filename)) {
    echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";

Leave a Comment