Home >Backend Development >PHP Problem >How to determine if a folder exists in php and create it if it does not exist

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

藏色散人
藏色散人Original
2020-10-06 10:20:165898browse

php determines whether the folder exists, and creates it if it does not exist: first create a PHP sample file; then define a mkdirs method; finally use the "mkdirs("aa01");" method to determine the folder and create it Just create it.

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

Recommended: "PHP Video Tutorial"

php determines whether the folder exists and then creates it

The code is as follows:

function mkdirs($dir, $mode = 0777)
{
    if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE;
    if (!mkdirs(dirname($dir), $mode)) return FALSE;
    return @mkdir($dir, $mode);
} 
mkdirs("aa01");

The default mode is 0777, which means the maximum possible access rights.

The above is the detailed content of How to determine if a folder 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