Home arrow PHP arrow Page 2 - Getting File System Data with PHP

Access and Modification Times - PHP

In this third part of an eight-part article series on using PHP to work with the file and operating system, you'll learn how to retrieve the size of a directory and find out a file's last access and modification times. This article is excerpted from chapter 10 of the book Beginning PHP and PostgreSQL 8: From Novice to Professional, written by W. Jason Gilmore and Robert H. Treat (Apress; ISBN: 1590595475).

  1. Getting File System Data with PHP
  2. Access and Modification Times
By: Apress Publishing
Rating: starstarstarstarstar / 0
November 15, 2011

print this article



The ability to determine a file's last access and modification time plays an important role in many administrative tasks, especially in Web applications that involve network or CPU-intensive update operations. PHP offers three functions for determining a file's access, creation, and last modification time, all of which are introduced in this section.


int fileatime (string filename)

The fileatime() function returns filename's last access time in Unix timestamp format, or FALSE on error. An example follows:

$file = "/usr/local/apache2/htdocs/book/chapter10/stat.php";
echo "File last accessed: ".date("m-d-y g:i:sa", fileatime($file));

This returns:

--------------------------------------------File last accessed: 06-09-03 1:26:14pm


int filectime (string filename)

The filectime() function returns filename's last changed time in Unix timestamp format, or FALSE on error. An example follows:

$file = "/usr/local/apache2/htdocs/book/chapter10/stat.php";
echo "File inode last changed: ".date("m-d-y g:i:sa", fileatime($file));

This returns:

--------------------------------------------File inode last changed: 06-09-03 1:26:14pm

Note The "last changed time" differs from the "last modified time" in that the last changed time refers to any change in the file's inode data, including changes to permissions, owner, group, or other inode-specific information, whereas the last modified time refers to changes to the file's content (specifically, byte size).


int filemtime (string filename)

The filemtime() function returns filename's last modification time in Unix timestamp format, or FALSE otherwise. The following code demonstrates how to place a "last modified timestamp" on a Web page:

$file = "/usr/local/apache2/htdocs/book/chapter10/stat.php";
echo "File last updated: ".date("m-d-y g:i:sa", filemtime($file));

This returns:

--------------------------------------------File last updated: 06-09-03 1:26:14pm

>>> More PHP Articles          >>> More By Apress Publishing

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: