Home > Backend Development > PHP Tutorial > How to get file attributes in PHP? Introduction to the method of getting file attributes in PHP (with code)

How to get file attributes in PHP? Introduction to the method of getting file attributes in PHP (with code)

不言
Release: 2023-04-03 10:52:01
Original
4563 people have browsed it

PHP can use a variety of functions to obtain file attributes. Each function allows us to obtain various information about the file. Next, let's take a look at the different methods of obtaining file attributes in PHP.

PHP gets file attributes to get the latest modification time:

< ?php  
$file = &#39;test.txt&#39;;  
echo date(&#39;r&#39;, filemtime($file));  
?>
Copy after login

The returned timestamp is the unix timestamp, which is commonly used in caching technology.

Related PHP gets file attributes There is the time fileatime() and filectime() are used to obtain the last accessed time. When the file's permissions, owner, all groups or other metadata in the inode are updated, the fileowner() function returns the file owner

$owner = posix_getpwuid(fileowner($file));
Copy after login

(Non-window system), ileperms() gets the permissions of the file,

< ?php  
$file = &#39;dirlist.php&#39;;  
$perms = substr(sprintf(&#39;%o&#39;, fileperms($file)), -4);  
echo $perms;  
?>
Copy after login

filesize() returns the number of bytes of the file size:

< ?php  
// 输出类似:somefile.txt: 1024 bytes  
$filename = &#39;somefile.txt&#39;;  
echo $filename . &#39;: &#39; . filesize($filename) . &#39; bytes&#39;;  
?>
Copy after login

PHP gets all the information about the file attributes and returns Array function stat() function:

< ?php  $file = &#39;dirlist.php&#39;;  $perms = stat($file);  var_dump($perms);  ?>
Copy after login

Related recommendations:

PHP How to get the protected attribute

The above is the detailed content of How to get file attributes in PHP? Introduction to the method of getting file attributes in PHP (with code). 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template