簡單介紹PHP獲取文件屬性方法
PHP獲取文件屬性可以用到多種函數(shù),來實(shí)現(xiàn)我們對文件各種不同信息的獲取需求。在這里我們就簡單的介紹了這些獲取方式的實(shí)現(xiàn)方法。#t#
PHP獲取文件屬性之獲取最近修改時(shí)間:
- < ?php
 - $file = 'test.txt';
 - echo date('r',
 
filemtime($file));- ?>
 
返回的說unix的時(shí)間戳,這在緩存技術(shù)常用.
相關(guān)PHP獲取文件屬性的還有獲取上次被訪問的時(shí)間fileatime(),filectime()當(dāng)文件的權(quán)限,所有者,所有組或其它 inode 中的元數(shù)據(jù)被更新時(shí)間,fileowner()函數(shù)返回文件所有者
$owner = posix_getpwuid(fileowner($file));
(非window系統(tǒng)),ileperms()獲取文件的權(quán)限,
- < ?php
 - $file = 'dirlist.php';
 - $perms = substr(sprintf
 
('%o', fileperms($file))
, -4);- echo $perms;
 - ?>
 
filesize()返回文件大小的字節(jié)數(shù):
- < ?php
 - // 輸出類似:somefile.txt:
 
1024 bytes- $filename = 'somefile.txt';
 - echo $filename . ': '
 
. filesize($filename) . ' bytes';- ?>
 
PHP獲取文件屬性的全部信息有個(gè)返回?cái)?shù)組的函數(shù)stat()函數(shù):
- < ?php
 - $file = 'dirlist.php';
 - $perms = stat($file);
 - var_dump($perms);
 - ?>
 















 
 
 
 
 
 
 