Example 1 — Check That a File Exists
Create a small file and confirm with is_file().
<?php
$file = sys_get_temp_dir() . '/is_file_demo.txt';
file_put_contents($file, 'Hello');
if (is_file($file)) {
echo "It is a file", PHP_EOL;
}
unlink($file); How It Works
- file_put_contents() creates a small text file in the temporary folder.
- is_file() finds the file and returns true.
- The message is printed.
- unlink() deletes the file again so nothing is left behind.

