How to modify file read and write permissions in php

青灯夜游
Release: 2023-03-09 21:28:01
Original
3264 people have browsed it

In PHP, you can use the chmod() function to modify the file read and write permissions. The function of this function is to change the permissions of the specified file; the syntax format is "chmod(file,mode)", and the parameter file specifies the Check the file, the parameter mode specifies new permissions.

How to modify file read and write permissions in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php changes the read and write permissions of the file

Copy after login

Related function description:

chmod() function changes the permissions of the specified file. Returns TRUE if successful, FALSE if failed.

Syntax

chmod(file,mode)
Copy after login

chmod will try to change the mode of the file specified by file to that given by mode.

ParametersDescription
fileRequired. Specifies the documents to be checked.
modeRequired. Specify new permissions.

The mode parameter consists of 4 numbers:

  • The first number is usually 0
  • The second number specifies the owner's permissions
  • The third The first number specifies the permissions of the user group to which the owner belongs
  • The fourth number specifies the permissions of everyone else

Possible values ​​(if you need to set multiple permissions, please set the following Total the numbers):

  • 1 = Execute permission
  • 2 = Write permission
  • 4 = Read permission

Note: mode will not be automatically treated as an octal value, and strings (such as "g w") cannot be used. To ensure correct operation, you need to add 0 in front of the mode:

Copy after login

The mode parameter contains three octal numbers in order to specify the owner, the owner's group, and everyone's access restrictions. Each part can be calculated by adding the required permissions. The number 1 makes the file executable, the number 2 makes the file writable, and the number 4 makes the file readable. Add these numbers to specify the required permissions.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to modify file read and write permissions in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!