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 change the permission of mkdir in php

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

Share

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

Editor to share with you how to change the permissions of mkdir in php, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Php mkdir methods to modify permissions: 1, create a PHP sample file; 2, through the "mkdir ('. / xw/'); chmod ('. / xw/',0777);" method to create a directory with read and write permissions.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

The permission problem of mkdir () function in php

Problem description:

A directory is created with the following php code. The expected permissions of the directory are 0777, but the actual result is 0755.

Mkdir ('. / aa/',0777)

Analysis and test results:

The directory permissions specified by the 1.mkdir () function can only be less than or equal to the default permissions set by the system umask.

For example, the default umask of linux is 0022, that is, the default permission to create a directory is 0755, so the permission for php mkdir ('. / aa/',0777) to get the directory is 0755.

Xw@xw-X201:~/Desktop/dd/aa$ umask0022xw@xw-X201:~/Desktop/dd/aa$ php-r "mkdir ('. / xw/',0777);" xw@xw-X201:~/Desktop/dd/aa$ php-r "mkdir ('. / xw1/',0755);" xw@xw-X201:~/Desktop/dd/aa$ php-r "mkdir ('. / xw2/',0747) "Total xw@xw-X201:~/Desktop/dd/aa$ ll usage 20drwxrwxrwx 5 xw xw 4096 2012-06-01 11:58. / drwxr-xr-x 6 xw xw 4096 2012-06-01 11:26.. / drwxr-xr-x 2 xw xw 4096 2012-06-01 11:57 xw/drwxr-xr-x 2 xw xw 4096 2012-06-01 11:58 xw1/drwxr--r-x 2 xw xw 4096 2012-06-01 11:58 xw2/

Change the default permissions of the system to 777m _ mkdir () to specify more permissions.

Xw@xw-X201:~/Desktop/dd/aa$ umask 000xwMuyxwMeixwMeixWAUZAAA $php-r "mkdir ('. / xw2/',0777);" xw@xw-X201:~/Desktop/dd/aa$ ll Total usage 12drwxrwxrwx 3 xw xw 4096 2012-06-01 12:08. / drwxr-xr-x 6 xw xw 4096 2012-06-01 11:26.. / drwxrwxrwx 2 xw xw 4096 2012-06-01 12:08 xw2/

The 2.chmod () function is not affected by the system umask and can set permissions greater than the default permissions of the system.

Xw@xw-X201:~/Desktop/dd/aa$ umask0022xw@xw-X201:~/Desktop/dd/aa$ php-r "mkdir ('. / xw1/',0777);" xw@xw-X201:~/Desktop/dd/aa$ php-r "mkdir ('. / xw2/');" xw@xw-X201:~/Desktop/dd/aa$ php-r "mkdir ('. / xw3/'); chmod ('. / xw3/',0777) "Total xw@xw-X201:~/Desktop/dd/aa$ ll usage 20drwxrwxrwx 5 xw xw 4096 2012-06-01 12:12. / drwxr-xr-x 6 xw xw 4096 2012-06-01 11:26.. / drwxr-xr-x 2 xw xw 4096 2012-06-01 12:11 xw1/drwxr-xr-x 2 xw xw 4096 2012-06-01 12:11 xw2/drwxrwxrwx 2 xw xw 4096 2012-06-01 12:12 xw3/

3. The system's mkdir command can set permissions greater than the default value.

Xw@xw-X201:~/Desktop/dd/aa$ umask0022xw@xw-X201:~/Desktop/dd/aa$ mkdir-m0777 xwxw@xw-X201:~/Desktop/dd/aa$ ll Total usage 12drwxrwxrwx 3 xwxw 4096 2012-06-01 12:18. / drwxr-xr-x 6 xwxw 4096 2012-06-01 11:26.. / drwxrwxrwx 2xw xw 4096 2012-06-01 12:18 xw/

Summary:

If php wants to create a directory with read and write permissions, it is best to use the following code instead of using the mkdir function to specify permissions directly to avoid the influence of system umask

Mkdir ('. / xw/'); chmod ('. / xw/',0777). These are all the contents of the article "how to change the permissions of mkdir in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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