PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

filegroup> <fileatime
Last updated: Fri, 29 Aug 2008

view this page in

filectime

(PHP 4, PHP 5)

filectimeRenvoie la date de dernier accès à un inode

Description

int filectime ( string $filename )

Renvoie la date de dernier accès à un inode d'un fichier.

Liste de paramètres

filename

Chemin vers le fichier.

Valeurs de retour

Renvoie la date à laquelle l'inode a été accédé pour la dernière fois, ou FALSE en cas d'erreur. L'heure est retournée sous la forme d'un timestamp Unix.

Exemples

Exemple #1 Exemple avec filectime()

<?php

// Affiche : somefile.txt a été modifié le : December 29 2002 22:16:23.

$filename 'somefile.txt';
if (
file_exists($filename)) {
    echo 
"$filename a été modifié le : " date("F d Y H:i:s."filectime($filename));
}

?>

Notes

Note: Sur la plupart des serveurs UNIX, un fichier est considéré comme modifié si les données de son inode sont modifiées. C'est-à-dire lorsque les permissions (utilisateur, groupe ou autre) ont été modifiées. Voyez aussi filemtime() (que vous pourrez utiliser lorsque vous créerez des indications telles que "Dernière modification : " sur les pages web) et fileatime().

Note: Notez aussi que sur certains systèmes UNIX, le ctime d'un fichier texte est considéré comme sa date de création. Cela est faux ! Il n'y a pas de date de création de fichier sous la plupart des systèmes UNIX.

Note: Les résultats de cette fonction sont mis en cache. Voyez la fonction clearstatcache() pour plus de détails.

Astuce

Depuis PHP 5.0.0, cette fonction peut aussi être utilisée avec quelques protocoles url. Lisez Liste des protocoles supportés pour une liste des protocoles supportant la famille de fonctionnalités de stat().

Voir aussi



filegroup> <fileatime
Last updated: Fri, 29 Aug 2008
 
add a note add a note User Contributed Notes
filectime
rich at rmbwebs dot com
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 />';
}
?>
simraLIAS at mac dot com
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 />';
}
?>
chuck dot reeves at gmail dot com
02-Oct-2007 06:14
filectime running on windows reading a file from a samba share, will still show the last modified date.
website at us dot kaspersky dot com
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.
StevieMc at example dot com
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.
gyrbo[at]yahoo[dot]com
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.
laurent dot pireyn at wanadoo dot be
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.

filegroup> <fileatime
Last updated: Fri, 29 Aug 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites