filectime

(PHP 4, PHP 5)

filectimeGets inode change time of file

Description

int filectime ( string $filename )

Gets the inode change time of a file.

Parameters

filename

Path to the file.

Return Values

Returns the time the file was last changed, or FALSE on failure. The time is returned as a Unix timestamp.

Examples

Example #1 A filectime() example

<?php

// outputs e.g.  somefile.txt was last changed: December 29 2002 22:16:23.

$filename 'somefile.txt';
if (
file_exists($filename)) {
    echo 
"$filename was last changed: " date("F d Y H:i:s."filectime($filename));
}

?>

Errors/Exceptions

Upon failure, an E_WARNING is emitted.

Notes

Note:

Note: In most Unix filesystems, a file is considered changed when its inode data is changed; that is, when the permissions, owner, group, or other metadata from the inode is updated. See also filemtime() (which is what you want to use when you want to create "Last Modified" footers on web pages) and fileatime().

Note:

Note also that in some Unix texts the ctime of a file is referred to as being the creation time of the file. This is wrong. There is no creation time for Unix files in most Unix filesystems.

Note:

Note that time resolution may differ from one file system to another.

Note: The results of this function are cached. See clearstatcache() for more details.

Tip

As of PHP 5.0.0, this function can also be used with some URL wrappers. Refer to Supported Protocols and Wrappers to determine which wrappers support stat() family of functionality.

See Also

Коментарии

If you use filectime with a symbolic link, you will get the change time of the file actually linked to. To get informations about the link self, use lstat.
2001-09-27 08:01:28
http://php5.kiev.ua/manual/ru/function.filectime.html
This method gets all the files in a directory, and echoes them in the order of the date they were added (by ftp or whatever).

<?PHP
function dirList ($directory$sortOrder){

   
//Get each file and add its details to two arrays
   
$results = array();
   
$handler opendir($directory);
    while (
$file readdir($handler)) { 
        if (
$file != '.' && $file != '..' && $file != "robots.txt" && $file != ".htaccess"){
           
$currentModified filectime($directory."/".$file);
           
$file_names[] = $file;
           
$file_dates[] = $currentModified;
        }   
    }
       
closedir($handler);

   
//Sort the date array by preferred order
   
if ($sortOrder == "newestFirst"){
       
arsort($file_dates);
    }else{
       
asort($file_dates);
    }
   
   
//Match file_names array to file_dates array
   
$file_names_Array array_keys($file_dates);
    foreach (
$file_names_Array as $idx => $name$name=$file_names[$name];
   
$file_dates array_merge($file_dates);
   
   
$i 0;

   
//Loop through dates array and then echo the list
   
foreach ($file_dates as $file_dates){
       
$date $file_dates;
       
$j $file_names_Array[$i];
       
$file $file_names[$j];
       
$i++;
           
        echo 
"File name: $file - Date Added: $date. <br/>"";       
    }

}
?>

I hope this is useful to somebody.
2006-11-15 08:28:49
http://php5.kiev.ua/manual/ru/function.filectime.html
Line 37 of the code above has an error.

echo  "File name: $file - Date Added: $date. <br/>""; 

There is an extra "  after the <br/> that needs to be deleted in order for this code to work.
2007-08-31 13:51:38
http://php5.kiev.ua/manual/ru/function.filectime.html
filectime running on windows reading a file from a samba share, will still show the last modified date.
2007-10-02 12:14:28
http://php5.kiev.ua/manual/ru/function.filectime.html
Filemtime seems to return the date of the EARLIEST modified file inside a folder, so this is a recursive function to return the date of the LAST (most recently) modified file inside a folder.

<?php

// Only take into account those files whose extensions you want to show.
$allowedExtensions = array(
 
'zip',
 
'rar',
 
'pdf',
 
'txt'
);

function 
filemtime_r($path)
{
    global 
$allowedExtensions;
   
    if (!
file_exists($path))
        return 
0;
   
   
$extension end(explode("."$path));     
    if (
is_file($path) && in_array($extension$allowedExtensions))
        return 
filemtime($path);
   
$ret 0;
   
     foreach (
glob($path."/*") as $fn)
     {
        if (
filemtime_r($fn) > $ret)
           
$ret filemtime_r($fn);   
           
// This will return a timestamp, you will have to use date().
     
}
    return 
$ret;   
}

?>
2009-02-03 04:15:13
http://php5.kiev.ua/manual/ru/function.filectime.html
Note that on Windows systems, filectime will show the file creation time, as there is no such thing as "change time" in Windows.
2009-09-05 12:19:09
http://php5.kiev.ua/manual/ru/function.filectime.html
Under Windows you can use fileatime() instead of filectime().
2010-01-06 20:07:37
http://php5.kiev.ua/manual/ru/function.filectime.html
You should avoid feeding the function files without a path. This applies for filemtime() and possibly fileatime() as well. If you omit the path the command will fail with the warning "filectime(): stat failed for filename.php".
2011-01-23 16:42:57
http://php5.kiev.ua/manual/ru/function.filectime.html
If you need file creation time on Mac OS X:

<?php
if ($handle popen('stat -f %B ' escapeshellarg($filename), 'r')) {
   
$btime trim(fread($handle100));
    echo 
strftime("btime: %Y.%m.%d %H:%M:%S\n"$btime);
   
pclose($handle);
}
?>
2015-06-10 18:04:07
http://php5.kiev.ua/manual/ru/function.filectime.html

    Поддержать сайт на родительском проекте КГБ