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

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

藏色散人
Release: 2023-03-07 19:30:02
Original
2382 people have browsed it

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

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!

Related labels:
php
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