Home  >  Article  >  Backend Development  >  How to implement if in php to determine whether a folder exists

How to implement if in php to determine whether a folder exists

藏色散人
藏色散人Original
2020-11-24 09:49:132320browse

php method to implement if to determine whether a folder exists: first create a PHP sample file; then determine whether the folder exists through the "if (!mkdirs(dirname($dir), $mode))" method, If it does not exist, just create it.

How to implement if in php to determine whether a folder exists

Recommendation: "PHP Video Tutorial"

The operating environment of this tutorial: Windows 7 system, PHP version 5.6, This method works for all brands of computers.

php determines whether the folder exists, and creates it if it does not exist

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 possibility access rights. For more information about mode please read the chmod() page.

The above is the detailed content of How to implement if in php to determine whether a folder exists. 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