Knowledge Base

file_exists

Simple Example1

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

Another Example

if (!file_exists($fileName)) {
    echo "<span class=\"txtRed\">ERROR: The file $fileName does not exist</span>";
}

Create file if it doesn't exist2

if (!file_exists($fileName)) {
    fopen($fileName, "w") or die("Unable to open file!");
}