Home >Backend Development >PHP Problem >How to set permissions for a new folder in php

How to set permissions for a new folder in php

藏色散人
藏色散人Original
2021-03-01 09:44:522856browse

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.

How to set permissions for a new folder in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn