Home > Article > Backend Development > PHP determines whether a file exists in the specified directory
The content of this article is about PHP's determination of whether files exist in the specified directory. It has certain reference value. Now I share it with you. Friends in need can refer to it
/* 功能:判断某个目录下是否存在文件; 参数:$path —— 要进行判断的目录,使用绝对路径 返回值:存在 - true 不存在 - false */ function dir_exist_file($path) { if(!is_dir($path)) { return false; } else { $files = scandir($path); // 删除 "." 和 ".." unset($files[0]); unset($files[1]); // 判断是否为空 if(!empty($files[2])) { return true; }else{ return false; } } }
Related recommendations:
php determines whether the string contains an element value in the array
PHP determines whether the login is a mobile phone
PHP determines whether WeChat is opened or the browser opens
The above is the detailed content of PHP determines whether a file exists in the specified directory. For more information, please follow other related articles on the PHP Chinese website!