The definition and usage of PHP mkdir () function

Source: Internet
Author: User
When we want to add a multilevel directory to our site, we can use PHP function mkdir () to implement this function. Support to create Chinese catalog

The mkdir () function creates a directory. Returns true if successful, otherwise false is returned.

How to use:

mkdir (Path,mode,recursive,context)

Parameter description
Path is required. Specifies the name of the directory to create.
Mode required. Set permissions. The default is 0777.
Recursive required. Specifies whether recursive mode is set.
Context required. Specifies the environment for file handles. Context is a set of options for modifying the behavior of a stream.
MkDir () tries to create a new directory specified by path.
The default mode is 0777, which means the maximum possible access rights.

Example code (support for creating Chinese catalogs):

<?phpheader ("Content-type:text/html;charset=utf-8");//To create a multilevel directory $path= "dai/php/php learning";//To determine whether the directory exists, there is a hint, Do not exist then create directory if (Is_dir ($path)) {  echo "Sorry! Directory ". $path. "Already exists! ";} else{//The third parameter is "true" means can create multi-level directory, iconv prevent Chinese directory garbled $res=mkdir (Iconv ("UTF-8", "GBK", $path), 0777,true); if ($res) {echo "catalog $ Path creation succeeded ";} Else{echo "Directory $path creation Failed";}? >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.