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 = 'test.txt'; echo date('r', filemtime($file)); ?>
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));
(Non-window system), ileperms() gets the permissions of the file,
< ?php $file = 'dirlist.php'; $perms = substr(sprintf('%o', fileperms($file)), -4); echo $perms; ?>
filesize() returns the number of bytes of the file size:
< ?php // 输出类似:somefile.txt: 1024 bytes $filename = 'somefile.txt'; echo $filename . ': ' . filesize($filename) . ' bytes'; ?>
PHP gets all the information about the file attributes and returns Array function stat() function:
< ?php $file = 'dirlist.php'; $perms = stat($file); var_dump($perms); ?>
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!