Home  >  Article  >  Backend Development  >  How to set folder permissions in php

How to set folder permissions in php

王林
王林Original
2020-08-04 14:31:513523browse

How to set folder permissions in php: You can use the chmod() function to set it. The chmod() function is used to set the permissions of the specified file. It returns TRUE if successful and FALSE if failed, such as [chmod("test.txt", 0600);].

How to set folder permissions in php

#chmod() function changes the permissions of the specified file.

Returns TRUE if successful and FALSE if failed.

(Recommended tutorial: php graphic tutorial)

Syntax:

chmod(file,mode)

Parameters:

  • file Required. Specifies the documents to be checked.​

  • #mode Required. Specify new permissions.

#mode parameter consists of 4 numbers:

The first number is usually 0

The second number specifies the owner’s permissions

The third number specifies the permissions of the user group to which the owner belongs

The fourth number specifies the permissions of everyone else

(Video tutorial recommendation: php video tutorial )

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

1 = Execute permission

2 = Write permission

4 = Read permission

Code implementation:

<?php
// Read and write for owner, nothing for everybody else
chmod("test.txt",0600);

// Read and write for owner, read for everybody else
chmod("test.txt",0644);

// Everything for owner, read and execute for everybody else
chmod("test.txt",0755);

// Everything for owner, read for owner&#39;s group
chmod("test.txt",0740);
?>

The above is the detailed content of How to set folder permissions 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