Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a directory in PHP

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to create a directory in PHP". In daily operation, I believe many people have doubts about how to create a directory in PHP. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to create a directory in PHP". Next, please follow the editor to study!

The mkdir () function creates a directory

In PHP, we can create a directory through the mkdir () function.

In many cases, we need to create a new directory for daily development. The basic syntax format of the mkdir () function is as follows:

Mkdir (string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context])

Among them, it should be noted that:

If the mkdir () function runs successfully, the value returned is true;. If the function fails, the value returned is flase. Among so many parameters, $pathname represents the path to the location where the directory is created; the default value of $mode is 0777, which means the set directory permission, this parameter is composed of four numbers, and the default value of 0777 is the maximum access right. If the computer system is windows, $mode will be ignored.

Recursive is an optional parameter that is used to set the recursive mode. Context is also an optional parameter that specifies the file handle environment.

Let's continue to look at the setting of $mode. This parameter is made up of four digits, each of which has a different meaning. The first digit is usually 0, and the remaining three digits are used to specify permissions. They stipulate different permissions, the second is the owner, the third is the user group to which the owner belongs, and the fourth is everyone else.

Next, let's take a look at the application of the mkdir () function through an example, as follows:

For the above example, we want to create another directory named "1103" in the "C:\ Users\ Administrator\ Desktop\ 1.0\" directory through the mkdir () function, and the output is as follows:

And a directory called "1103" is created at the specified location:

Of course, we can also create a directory through different path expressions, as shown in the following example:

Before running the code, there is neither a directory for test nor a directory for demo in the peer directory of this file:

When the run is finished, the output is the same as the example above, and a new file is created:

When you run the code again, the output is:

After running the code, a test directory is created in the Tongji directory of the current file and a directory named demo is created in the test directory.

Among them, we also need to note that when we specify the location of the new directory creation, it cannot have the same name as the existing directory, if the same name, then the program user reported an error.

At this point, the study on "how to create a directory in PHP" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report