Home >Backend Development >PHP Problem >How to set permissions for a new folder in php
How to create a new folder in php and set permissions: first create the directory through "mkdir('./xw/');"; then use "chmod('./xw/',0777);" Just specify the permissions.
The operating environment of this article: linux5.9.8 system, PHP version 7.1, Dell G3 computer.
Mkdir and chmod in php create directory folder permissions
Environment nging php linux
Use mkdir("Road Jin",777 on the server ) directly created the folder, and found that the permission attribute only showed "d" after generation. Naturally, files could not be uploaded in this directory. Later, the code was modified to: mkdir("Lu Jin"); chmod("Lu Jin",777); The generated folder permission attribute is "drwxrwxrwx".
Summary:
If php wants to create a directory with read and write permissions, it is best to use the following code. Do not directly use the mkdir function to specify permissions to avoid the impact of the system umask
mkdir('./xw/'); chmod( './xw/',0777);
[Recommended learning: "PHP Video Tutorial"]
The above is the detailed content of How to set permissions for a new folder in php. For more information, please follow other related articles on the PHP Chinese website!