Check path is valid in PHP
The
file_exists()
function in PHP is an inbuilt function which is used to check whether a file or directory exists or not.The path of the file or directory you want to check is passed as a parameter to the file_exists() function which returns True on success and False on failure.
<?php
// checking whether file exists or not
echo file_exists('/user01/work/gfg.txt');
?>
Output
1
<?php
// checking whether file exists or not
$file_pointer = '/user01/work/gfg.txt';
if (file_exists($file_pointer))
{
echo "The file $file_pointer exists";
}
else
{
echo "The file $file_pointer does
not exists";
}
?>
Output
1