简单介绍PHP获取文件属性方法

开发 后端
PHP获取文件属性包括获取最近修改时间;获取上次被访问的时间;获取文件的权限;获取文件的全部信息等等。这些都可以通过不同的PHP函数来是是实现。

PHP获取文件属性可以用到多种函数,来实现我们对文件各种不同信息的获取需求。在这里我们就简单的介绍了这些获取方式的实现方法。#t#

PHP获取文件属性之获取最近修改时间:

 

  1. < ?php  
  2. $file = 'test.txt';  
  3. echo date('r', 
    filemtime($file));  
  4. ?> 

 

返回的说unix的时间戳,这在缓存技术常用.

相关PHP获取文件属性的还有获取上次被访问的时间fileatime(),filectime()当文件的权限,所有者,所有组或其它 inode 中的元数据被更新时间,fileowner()函数返回文件所有者

$owner = posix_getpwuid(fileowner($file));

(非window系统),ileperms()获取文件的权限,

 

  1. < ?php  
  2. $file = 'dirlist.php';  
  3. $perms = substr(sprintf
    ('%o', fileperms($file))
    , -4);  
  4. echo $perms;  
  5. ?> 
  6.  

 

filesize()返回文件大小的字节数:

  1. < ?php  
  2. // 输出类似:somefile.txt:
     1024 bytes  
  3. $filename = 'somefile.txt';  
  4. echo $filename . ': ' 
    . filesize($filename) . ' bytes';  
  5. ?> 
  6.  

 

PHP获取文件属性的全部信息有个返回数组的函数stat()函数:

 

  1. < ?php  
  2. $file = 'dirlist.php';  
  3. $perms = stat($file);  
  4. var_dump($perms);  
  5. ?> 
  6.  

 

 

责任编辑:曹凯 来源: 百度博客
相关推荐

2010-07-16 16:32:17

Perl文件

2010-03-05 13:31:02

Linux进程文件路径

2009-09-03 09:03:28

Linux操作系统文件属性命令介绍

2009-12-23 16:40:15

Linux文件属性

2009-12-11 15:17:52

PHP验证码调用

2009-10-12 12:41:04

Linux文件属性目录配置

2009-12-09 13:54:42

PHP Zend加密文

2009-11-23 15:10:28

PHP获取当前url

2011-07-11 10:00:34

PHP缓存技术

2009-11-30 18:34:22

PHP简单语法

2009-11-16 13:57:21

PHP上传文件

2009-10-28 14:43:01

linux文件属性

2011-07-15 14:29:44

PHPXML

2011-07-04 17:27:42

JSP

2009-12-10 09:33:05

PHP获取POST数据

2020-11-06 00:00:00

PHP技巧后门

2009-08-20 16:25:59

C# 匿名方法

2010-03-12 10:20:19

Fedora内核

2009-08-14 17:27:56

C#方法参数

2009-12-11 14:21:57

PHP获取字段属性
点赞
收藏

51CTO技术栈公众号