filectime

(PHP 4, PHP 5, PHP 7, PHP 8)

filectimeObtém o horário de modificação de inode do arquivo

Descrição

filectime(string $filename): int|false

Obtém o horário de modificação do inode de um arquivo.

Parâmetros

filename

Caminho para o arquivo.

Valor Retornado

Retorna o horário em que o arquivo foi modificado pela última vez, ou false em caso de falha. O horário é retornado como um timestamp Unix.

Erros/Exceções

Em caso de falha, um E_WARNING será emitido.

Exemplos

Exemplo #1 Exemplo de filectime()

<?php

// Exibe algo como: arquivo.txt foi modificado em: December 29 2002 22:16:23.

$filename = 'arquivo.txt';
if (
file_exists($filename)) {
echo
"$filename foi modificado em: " . date ("F d Y H:i:s.", filectime($filename));
}

?>

Notas

Nota:

Nota: Na maioria dos sistemas de arquivos Unix, um arquivo é considerado modificado quando seus dados de inode são modificados; isto é, quando as permissões, proprietário, grupo ou outros metadados do inode são atualizados. Consulte também filemtime() (que é usado quando se deseja criar rodapés de páginas web do tipo "Última Modificação") e fileatime().

Nota:

Note também que em alguns textos sobre Unix o horário de modificação de um arquivo é definido como sendo o horário de criação do arquivo. Isto está errado. Não existe horário de criação para arquivos na maioria dos sistemas de arquivos Unix.

Nota:

Note que a resolução de tempo pode variar de um sistema de arquivos para outro.

Nota: Os resultados desta função são armazenados em cache. Consulte a função clearstatcache() para mais detalhes.

Dica

A partir do PHP 5.0.0, esta função também pode ser usada com alguns wrappers URL. Consulte os Protocolos e Wrappers suportados para determinar quais wrappers suportam a família de funções stat().

Veja Também

  • filemtime() - Obtém o horário de modificação do arquivo

add a note add a note

User Contributed Notes 9 notes

up
13
StevieMc at example dot com
17 years ago
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.
up
2
website at us dot kaspersky dot com
16 years ago
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.
up
2
soapergem at gmail dot com
14 years ago
Note that on Windows systems, filectime will show the file creation time, as there is no such thing as "change time" in Windows.
up
1
faketruth at yandex dot ru
8 years ago
If you need file creation time on Mac OS X:

<?php
if ($handle = popen('stat -f %B ' . escapeshellarg($filename), 'r')) {
   
$btime = trim(fread($handle, 100));
    echo
strftime("btime: %Y.%m.%d %H:%M:%S\n", $btime);
   
pclose($handle);
}
?>
up
2
chuck dot reeves at gmail dot com
16 years ago
filectime running on windows reading a file from a samba share, will still show the last modified date.
up
1
m dot rabe at directbox dot com
14 years ago
Under Windows you can use fileatime() instead of filectime().
up
1
javi at live dot com
15 years ago
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;   
}

?>
up
1
coolkoon at gmail dot com
13 years ago
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".
up
0
laurent dot pireyn at wanadoo dot be
22 years ago
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.
To Top