Home > Article > Backend Development > How to set file permissions in php
The way to set file permissions in php is:
Use the chmod function
The mode parameter contains three octal numbers, which are specified in order. The owner, the owner's group, and access restrictions for everyone. 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.
<?php // Read and write for owner, nothing for everybody else chmod("/somedir/somefile", 0600); // Read and write for owner, read for everybody else chmod("/somedir/somefile", 0644); // Everything for owner, read and execute for others chmod("/somedir/somefile", 0755); // Everything for owner, read and execute for owner's group chmod("/somedir/somefile", 0750); ?>
Related references:php中文网
The above is the detailed content of How to set file permissions in php. For more information, please follow other related articles on the PHP Chinese website!