Home>Article>Backend Development> How to quickly know the size, type and permissions of the file in php file operations

How to quickly know the size, type and permissions of the file in php file operations

青灯夜游
青灯夜游 Original
2021-08-20 14:10:11 2618browse

In the previous article "php file operation: how to obtain the time attribute (information) of the file", we learned that we can use the built-in functions filectime(), filemtime, fileatime() to obtain separate files Three time attributes: creation time, modification time and last access time. Interested friends can learn about it~

The main content of this article is to understand the file size, file type and file/directory permissions method of obtaining. Let’s give you a detailed introduction to how to obtain it.

1. Get the size of the file

You can use thefilesize($filename)function to return the specified file$filenamethe size of. Returns the file size in bytes on success or FALSE on failure.

The output result is:

How to quickly know the size, type and permissions of the file in php file operations

2. Get the file type

You can usefiletype ($filename)The function returns the type of the specified file or directory$filename. If successful, one of the following 7 possible values will be returned:

  • fifo

  • ##char

  • ##dir
  • block
  • link
  • file
  • unknown
  • If failed, return FALSE.
{$filename} 文件的类型为:".filetype($filename); $filename = "D:/demo/img"; echo "
{$filename} 文件的类型为:".filetype($filename); ?>

The output result is:

How to quickly know the size, type and permissions of the file in php file operations

3. Obtain file permissions

You can use

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); ?>
The output result is:

How to quickly know the size, type and permissions of the file in php file operations# Description: 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
  • PHP Chinese website platform has a lot of video teaching resources. Welcome everyone to learn "
PHP Video Tutorial

"!

The above is the detailed content of How to quickly know the size, type and permissions of the file in php file operations. For more information, please follow other related articles on the PHP Chinese website!

php
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