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

How to set file permissions in php

王林
王林Original
2020-11-10 13:43:562926browse

How to set file permissions in php: You can use the chmod function to set file permissions, such as [chmod("/somedir/somefile", 0755);]. The chmod function is used to change the file mode and returns TRUE if successful.

How to set file permissions in php

Method:

chmod() function changes the file mode.

Returns TRUE if successful, otherwise returns FALSE.

Related video recommendations: java video tutorial

Syntax:

chmod(file,mode)

Parameters:

file Required. Specifies the documents to be checked.​

mode ​ Optional. Specify new permissions.

Code implementation:

<?php
chmod("/somedir/somefile", 0755); // 八进制数,正确的 mode 值
// 所有者可读写,其他人没有任何权限
chmod("test.txt",0600);
// 所有者可读写,其他人可读
chmod("test.txt",0644);
// 所有者有所有权限,其他所有人可读和执行
chmod("test.txt",0755);
// 所有者有所有权限,所有者所在的组可读
chmod("test.txt",0740);
?>

Related recommendations: php training

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