Home > Article > Backend Development > How to set folder permissions in php
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);].
#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'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!