Home  >  Article  >  Backend Development  >  PHP determines whether a file or directory exists_PHP tutorial

PHP determines whether a file or directory exists_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:01:181122browse

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 "
";
}


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445442.htmlTechArticlephp The method to determine whether a file or directory exists is very simple. PHP has its own function to determine whether a file or directory exists. file_existsWhether the file exists, to determine whether the directory exists we use is_...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn