Home>Article>Backend Development> How to quickly know the size, type and permissions of the file in php file operations
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$filename
the size of. Returns the file size in bytes on success or FALSE on failure.
The output result is:
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
{$filename} 文件的类型为:".filetype($filename); $filename = "D:/demo/img"; echo "
{$filename} 文件的类型为:".filetype($filename); ?>
The output result is:
3. Obtain file permissionsYou 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.
The output result is:<?php header("content-type:text/html;charset=utf-8"); $filename = "test.txt"; echo "{$filename} 文件的权限为:".fileperms($filename); ?>
# Description: The number representing permissions has three possible values. To set multiple permissions, you can use the following numbers. Total:
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!