Note that on Windows systems, filectime will show the file creation time, as there is no such thing as "change time" in Windows.
filectime
(PHP 4, PHP 5)
filectime — Haalt de 'inode verander' tijd op van een bestand
Beschrijving
Geeft de tijd dat het bestand het laatste veranderd is terug, of FALSE in het geval van een fout. De tijd wordt terug gegeven in Unix timestamp.
Let op: op de meeste Unix bestands systemen wordt een file als gewijzigd gezien, als zijn inode data is gewijzigd; dat wil zeggen, wanneer de permissie, eigenaar, groep of andere metadata van de inode geupdate wordt. Zie ook filemtime() (dit wil je gebruiken als je "Laatst veranderd" voetnoten wil maken op je webpagina) en fileatime().
Let ook op het feit dat in sommige Unix teksten staat dat de ctime van een bestand de tijd van aanmaak van het bestand is. Dit is fout. Er is geen aanmaak tijd voor Unix bestanden in de meeste Unix bestands systemen.
Note: The results of this function are cached. See clearstatcache() for more details.
Note: This function will not work on remote files as the file to be examined must be accessible via the servers filesystem.
Example#1 fileatime() voorbeeld
<?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));
}
?>
Zie ook filemtime().
filectime
05-Sep-2009 06:19
03-Feb-2009 11:15
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;
}
?>
11-Mar-2008 09:07
This is a modification of simraLIAS at mac dot com's code.
Modification dates should not be used for keys in an array when sorting by date because there is no guarantee that all files will have different dates. Collisions resulting in files missing from the list could be possible. A better way is to use the filename as the key (guaranteed to not be collisions)
<?php
foreach (glob("../downloads/*") as $path) { //configure path
$docs[$path] = filectime($path);
} asort($docs); // sort by value, preserving keys
foreach ($docs as $path => $timestamp) {
print date("d. M. Y: ", $timestamp);
print '<a href="'. $path .'">'. basename($path) .'</a><br />';
}
?>
30-Nov-2007 12:24
This is another way to get a list of files ordered by upload time:
<?php
foreach (glob("../downloads/*") as $path) { //configure path
$docs[filectime($path)] = $path;
} ksort($docs); // sort by key (timestamp)
foreach ($docs as $timestamp => $path) {
print date("d. M. Y: ", $timestamp);
print '<a href="'. $path .'">'. basename($path) .'</a><br />';
}
?>
02-Oct-2007 06:14
filectime running on windows reading a file from a samba share, will still show the last modified date.
31-Aug-2007 07:51
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.
15-Nov-2006 03:28
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.
22-Sep-2002 01:35
filectime doesn't seem to be working properly on Win32 systems (it seems to return the creation time). Try using filemtime if you have problems.
27-Sep-2001 02:01
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.
