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

How to set file permissions in php

WJ
WJOriginal
2020-06-01 13:20:013280browse

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&#39;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!

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