Home > Backend Development > PHP Problem > How to check the permission settings of a file in php

How to check the permission settings of a file in php

青灯夜游
Release: 2023-03-13 16:12:01
Original
2798 people have browsed it

In PHP, you can use the fileperms() function to view the permission settings of the file. The function of this function is to obtain and return the permissions of the file or directory. The syntax is "fileperms(filename)"; if the acquisition is successful, then Returns the file's permission settings as a number.

How to check the permission settings of a file in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In PHP, you can use the fileperms() function to view the file permission settings.

fileperms($filename) The function returns the permissions of the file or directory $filename. If successful, the permissions are returned as a number. On failure, returns FALSE.

<?php
header("content-type:text/html;charset=utf-8");
$filename = "test.txt";
echo "{$filename} 文件的权限为:".fileperms($filename);
?>
Copy after login

The output result is:

How to check the permission settings of a file in php

#Note: The number representing permissions has three possible values. To set multiple permissions, you can use the following numbers. Total:

  • 1 = Execute permission

  • #2 = Write permission

  • 4 = Read permission

Example:

  • 5 = 4 1 = Read execution permission

  • 6 = 4 2 = Read and write permissions

  • 7 = 4 2 1 = Read and write execution permissions, that is, all permissions are provided

Recommended learning : "PHP Video Tutorial"

The above is the detailed content of How to check the permission settings of a file in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template