PHP uses mkdir to create multilevel catalogs _php tips

Source: Internet
Author: User
Tags mkdir

This example describes how PHP uses mkdir to create a multilevel catalog. Share to everyone for your reference, specific as follows:

PHP uses mkdir () to create a multilevel directory, which is very useful compared to your own first-level creation.

The following is a description of the functions in the PHP manual:

Copy Code code as follows:
BOOL MkDir (string $pathname [, int $mode = 0777 [, bool $recursive = False [, resource $context]]]

The return value is of type bool.

First parameter: must, represents the path of the multilevel directory to be created;

The second parameter: Set the directory permissions, the default is 0777, meaning the most likely access rights;

Third parameter: True indicates that multilevel catalogs are allowed to be created.

Note: You can create a Chinese catalog

Copy Code code as follows:
mkdir (Iconv ("Utf-8", "GBK", $path), 0777,true);
Need to use Iconv transcoding

The complete sample code is as follows:

<?php
  Header ("Content-type:text/html;charset=utf-8");
  The multilevel directory to create
  $path = "dai/php/php learning";
  To determine whether a directory exists, give a hint, and do not exist create a directory
  if (Is_dir ($path)) { 
    echo "Sorry!" Directory. $path. "Already there!" ";
  } else{
    //The third parameter is "true" to create a multilevel directory, iconv prevent Chinese directory garbled
    $res =mkdir (iconv ("UTF-8", "GBK", $path), 0777,true); 
    if ($res) {
      echo "directory $path create Success";
    } else{
      echo "directory $path create Failed";
    }
? >

I hope this article will help you with the PHP program design.

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.