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

How to create a php directory if it does not exist

藏色散人
藏色散人 Original
2020-07-31 09:46:36 3754browse

The implementation method of creating a php directory if it does not exist: first define a "mkdirs" method; then use the if statement to determine whether the directory exists; finally create the file through the mkdir method.

How to create a php directory if it does not exist

Recommended: "PHP Video Tutorial"

If the php directory does not exist, create it:

The code is as follows:

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

Description: The program determines whether the directory a1 exists. If it exists, it returns true. If it does not exist, it creates the directory a1. By default, it gives read, write and execute permissions. .

Note: 777 permissions are applicable to Linux environment.

The above is the detailed content of How to create a php directory 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