Home > Backend Development > PHP Problem > 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

藏色散人
Release: 2023-03-10 19:00:01
Original
4590 people have browsed it

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

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!

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