php获取文件属性可以用多种函数来实现,每种函数都可以让我们能获取文件的各种不同信息,接下来我们就来看看关于php获取文件属性的不同方法。
PHP获取文件属性之获取最近修改时间:
< ?php
$file = 'test.txt';
echo date('r', filemtime($file));
?>返回的说unix的时间戳,这在缓存技术常用.
相关PHP获取文件属性的还有获取上次被访问的时间fileatime(),filectime()当文件的权限,所有者,所有组或其它 inode 中的元数据被更新时间,fileowner()函数返回文件所有者
$owner = posix_getpwuid(fileowner($file));
(非window系统),ileperms()获取文件的权限,
立即学习“PHP免费学习笔记(深入)”;
< ?php
$file = 'dirlist.php';
$perms = substr(sprintf('%o', fileperms($file)), -4);
echo $perms;
?>filesize()返回文件大小的字节数:
< ?php // 输出类似:somefile.txt: 1024 bytes $filename = 'somefile.txt'; echo $filename . ': ' . filesize($filename) . ' bytes'; ?>
PHP获取文件属性的全部信息有个返回数组的函数stat()函数:
< ?php $file = 'dirlist.php'; $perms = stat($file); var_dump($perms); ?>
相关推荐:
以上就是PHP如何获取文件属性?php获取文件属性的方法介绍(附代码)的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号