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

How to create a php directory if it does not exist

藏色散人
Release: 2023-03-03 15:24:01
Original
3922 people have browsed it

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

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!

Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template