Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Filesystem Functions : filectime

filectime

Gets inode change time of file (PHP 4, PHP 5)
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 in case of an error. The time is returned as a Unix timestamp.

Examples

Example 632. 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));
}

?>


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:

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 Appendix O, List of Supported Protocols/Wrappers for a listing of which wrappers support stat() family of functionality.

See Also
filemtime()

Related Examples ( Source code ) » filectime


Code Examples / Notes » filectime

steviemc

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.


website

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.


laurent dot pireyn

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.

chuck dot reeves

filectime running on windows reading a file from a samba share, will still show the last modified date.

gyrbo

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.

Change Language


Follow Navioo On Twitter
basename
chgrp
chmod
chown
clearstatcache
copy
delete
dirname
disk_free_space
disk_total_space
diskfreespace
fclose
feof
fflush
fgetc
fgetcsv
fgets
fgetss
file_exists
file_get_contents
file_put_contents
file
fileatime
filectime
filegroup
fileinode
filemtime
fileowner
fileperms
filesize
filetype
flock
fnmatch
fopen
fpassthru
fputcsv
fputs
fread
fscanf
fseek
fstat
ftell
ftruncate
fwrite
glob
is_dir
is_executable
is_file
is_link
is_readable
is_uploaded_file
is_writable
is_writeable
lchgrp
lchown
link
linkinfo
lstat
mkdir
move_uploaded_file
parse_ini_file
pathinfo
pclose
popen
readfile
readlink
realpath
rename
rewind
rmdir
set_file_buffer
stat
symlink
tempnam
tmpfile
touch
umask
unlink
eXTReMe Tracker