Home  >  Article  >  Backend Development  >  How to determine if a directory exists in php and create it if it does not exist

How to determine if a directory exists in php and create it if it does not exist

藏色散人
藏色散人Original
2021-06-21 09:28:234478browse

php method to determine whether the directory exists, and create it if it does not exist: first create a PHP sample file; then use the "function mkFolder($path){...}" method to determine whether the directory exists, and if it does not exist, then Just create the function.

How to determine if a directory exists in php and create it if it does not exist

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

How does PHP determine whether a directory exists or create it if it does not exist?

PHP determines whether the directory exists. If it does not exist, create it.

The code is as follows:

function mkFolder($path)
{
    if(!is_readable($path))
    {
        is_file($path) or mkdir($path,0700);
    }
}

is_file() function checks whether the specified file name is a normal file.

mkdir() function creates a directory. Returns true if successful, false otherwise.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to determine if a directory exists in php and create it if it does not exist. For more information, please follow other related articles on the PHP Chinese website!

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