首頁  >  文章  >  後端開發  >  PHP如何取得檔案屬性?php取得檔案屬性的方法介紹(附程式碼)

PHP如何取得檔案屬性?php取得檔案屬性的方法介紹(附程式碼)

不言
不言原創
2018-07-23 15:20:504464瀏覽

PHP取得檔案屬性可以用多種函數來實現,每種函數都可以讓我們能取得檔案的各種不同信息,接下來我們就來看看關於PHP取得檔案屬性的不同方法。

PHP取得檔案屬性之獲取最近修改時間:

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

傳回的說unix的時間戳記,這在快取技術常用.

相關PHP取得檔案屬性的還有取得上次被存取的時間fileatime(),filectime()當檔案的權限,擁有者,所有群組或其它inode 中的元資料被更新時間,fileowner()函數傳回檔案擁有者

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

(非window系統),ileperms()取得檔案的權限,

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

filesize()傳回檔案大小的位元組數:

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

PHP取得檔案屬性的全部資訊都有個返回陣列的函數stat()函數:

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

 相關建議:

PHP 如何取得protected屬性

#

以上是PHP如何取得檔案屬性?php取得檔案屬性的方法介紹(附程式碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn