Skip to content
PHP Logo

How can PHP be used to check if a file with a specific name already exists on the server?

To check if a file with a specific name already exists on the server using PHP, you can use the `file_exists()` function. This function takes the file path as an argument and returns `true` if the file exists and `false` if it does not. You can then use this boolean value to determine if the file exists or not.

php
$filename = 'example.txt';

if (file_exists($filename)) {
    echo 'File exists.';
} else {
    echo 'File does not exist.';
}