PHP has a very simple method to determine whether a file or directory exists. PHP has its own function to determine whether a file or directory exists. File_exists file exists. To determine whether a directory exists, we can use is_dir.
php tutorial to determine whether a file or directory exists
The method is very simple. PHP has its own function to determine whether a file or directory exists. File_exists file exists. To determine whether a directory exists, we use is_dir and it is ok.
*/
$file = "data.txt";
$dir = "www.bkjia.com/newdata";if(file_exists($file))
{
echo "In the current directory, the file ".$file." exists";
echo "
";
}
else
{
echo "The file ".$file." does not exist in the current directory";
echo "
";
}
echo "
";
echo "
";
echo "
";
if(is_dir($dir))
{
echo "Under the current directory, the directory ".$dir." exists";
echo "
";
}
else
{
echo "Under the current directory, the directory ".$dir." does not exist";
echo "
";
}