Home > Backend Development > PHP Tutorial > PHP怎么判断文件或目录是否存在?

PHP怎么判断文件或目录是否存在?

PHPz
Release: 2020-09-04 17:32:07
Original
2087 people have browsed it

PHP怎么判断文件或目录是否存在?

php 判断文件或目录是否存在

判断文件或目录是否存在有自带的函数

file_exists:文件是否存在

$file = "check.txt";

if(file_exists($file))
{
    echo "当前目录中,文件".$file."存在";
}
else
{
     echo "当前目录中,文件".$file."不存在";
}
Copy after login

is_dir:目录是否存在

$dir = "c:/datacheck";

if(is_dir($dir))
{
    echo "当前目录下,目录".$dir."存在";
}
else
{
     echo "当前目录下,目录".$dir."不存在";
}
Copy after login

更多相关知识,请访问 PHP中文网!!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template