Definition and usage of php mkdir() function

怪我咯
Release: 2023-03-13 14:58:02
Original
1496 people have browsed it

When we want to add multi-level directories to our site, we can use php function mkdir() to achieve this function. Supports creating Chinese directories

mkdir() FunctionCreate a directory. Returns true if successful, false otherwise.

Usage:

mkdir(path,mode,recursive,context)
Copy after login

Parameter Description
path Required. Specifies the name of the directory to be created.
mode required. Specify permissions. The default is 0777.
recursive Required. Specifies whether to set recursive mode.
context Required. Specifies the environment for a file handle. Context is a set of options that can modify the behavior of a stream.
mkdir() attempts to create a new directory specified by path.
The default mode is 0777, which means the greatest possible access.

Example code (supports creating Chinese directories):

<?php
header("Content-type:text/html;charset=utf-8");
//要创建的多级目录
$path="dai/php/php学习";
//判断目录存在否,存在给出提示,不存在则创建目录
if (is_dir($path)){  
echo "对不起!目录 " . $path . " 已经存在!";
}else{
//第三个参数是“true”表示能创建多级目录,iconv防止中文目录乱码
$res=mkdir(iconv("UTF-8", "GBK", $path),0777,true); 
if ($res){
echo "目录 $path 创建成功";
}else{
echo "目录 $path 创建失败";
}
}

?>
Copy after login


The above is the detailed content of Definition and usage of php mkdir() function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!