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

search for in the

filegroup> <fileatime
Last updated: Fri, 20 May 2011

view this page in

filectime

(PHP 4, PHP 5)

filectimeObtiene el momento del último cambio del i-nodo de un archivo

Descripción

int filectime ( string $filename )

Obtiene el momento del último cambio del i-nodo de un archivo.

Parámetros

filename

Ruta del archivo.

Valores devueltos

Devuelve el momento en que se modificó un archivo por última vez, o FALSE en caso de error. El momento es devuelto como tiempo Unix.

Ejemplos

Example #1 Un ejemplo de filectime()

<?php

// muestra, p.ej.  La última modificación de archivo.txt fue: December 29 2002 22:16:23.

$nombre_archivo 'archivo.txt';
if (
file_exists($nombre_archivo)) {
    echo 
"La última modificación de $nombre_archivo fue: " date("F d Y H:i:s."filectime($nombre_archivo));
}

?>

Errores/Excepciones

En caso de fallo, se emite un E_WARNING.

Notas

Note:

Anotación: En la mayoría de los sistemas de archivos Unix, un archivo se considera modificado cuando su información de i-nodo se cambia; es decir, cuando los permisos, propietario, grupo, u otra meta-información del i-nodo es acualizada. Véase también filemtime() (la cual es la que se querrá usar cuando se desee crear pies de página como "Última Modificación" en páginas web) y fileatime().

Note:

Observe también que en algunos textos Unix el ctime de un archivo se refiere al momento de creación del archivo. Esto es erróneo. No hay momento de creación de archivos Unix en la mayoría de sistemas de archivos Unix.

Note:

Observe que el tiempo de resolución quizá varia según el sistema de ficheros.

Note: Los resultados de esta función son guardados en caché. Para más información ver clearstatcache().

Tip

Desde PHP 5.0.0, esta función también puede usarse con algunos URL wrappers. Consultar Protocolos y Envolturas soportados para obtener una lista los wrappers tienen soporte para la familia de funcionalidad de stat().

Ver también

  • filemtime() - Obtiene el momento de la última modificación de un archivo



filegroup> <fileatime
Last updated: Fri, 20 May 2011
 
add a note add a note User Contributed Notes filectime
coolkoon at gmail dot com 23-Jan-2011 10:42
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".
m dot rabe at directbox dot com 07-Jan-2010 02:07
Under Windows you can use fileatime() instead of filectime().
soapergem at gmail dot com 05-Sep-2009 04:19
Note that on Windows systems, filectime will show the file creation time, as there is no such thing as "change time" in Windows.
javi at live dot com 03-Feb-2009 10: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;   
}

?>
rich at rmbwebs dot com 11-Mar-2008 08: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 11: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 04: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 05: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 02: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 21-Sep-2002 11: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 12: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.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites