Home > Backend Development > PHP Tutorial > PHP determines whether a file exists in the specified directory

PHP determines whether a file exists in the specified directory

不言
Release: 2023-03-25 07:40:02
Original
6162 people have browsed it

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;
            }
        }
    }
Copy after login

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!

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