Home > Article > Backend Development > The mkdir() function in PHP is used to create directories
The mkdir() function in PHP is used to create a directory. A specific code example will be given below.
First of all, we need to understand the basic usage of the mkdir() function. The prototype of the mkdir() function is:
bool mkdir(string $directory, int $mode = 0777, bool $recursive = false, resource $context = null)
Parameter description:
The following is a specific code example:
// Create directory
$dir = "/path/to/directory"; / / Set the directory path to be created
if (!file_exists($dir)) { // Determine whether the directory already exists
if (mkdir($dir, 0777, true)) { // 使用 mkdir() 函数创建目录 echo "目录创建成功!"; } else { echo "目录创建失败!"; }
} else {
echo "目录已存在!";
}
?>
Note:
The above is a simple code example, you can modify and extend it according to your needs. Hope it helps you!
The above is the detailed content of The mkdir() function in PHP is used to create directories. For more information, please follow other related articles on the PHP Chinese website!