★ wanayoo — archive 1999 http://fr.php.net/manual/hu/function.filemtime.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<fileinodefileowner>
view the version of this page
Last updated: Tue, 16 Nov 2004

filemtime

(PHP 3, PHP 4 , PHP 5)

filemtime -- Gets file modification time

Description

int filemtime ( string filename)

Returns the time the file was last modified, or FALSE in case of an error. The time is returned as a Unix timestamp, which is suitable for the date() function.

Megjegyzés: Eme függvény eredményei elsőként csupán a gyorstárba kerülnek, nem lesznek azonnali hatással a fájlrendszerre. További információk a clearstatcache() oldalon olvashatók.

Tipp: Az PHP 5.0.0 változattól kezdődően ez a függvény néhány URL burkolóval megadott erőforrással is együttműködik. A L Függelék oldalon olvasható azon burkolók listája, amelyek támogatják a stat() és hasonlatos függvényeket.

This function returns the time when the data blocks of a file were being written to, that is, the time when the content of the file was changed.

Példa 1. filemtime() example

<?php
// outputs e.g.  somefile.txt was last modified: December 29 2002 22:16:23.

$filename = 'somefile.txt';
if (
file_exists($filename)) {
   echo
"$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}
?>

See also filectime(), stat(), touch(), and getlastmod().



add a note add a note User Contributed Notes
filemtime
aidan at php dot net
26-Oct-2004 02:42
If you're looking to convert timestamps to a duration, for example "10" to "10 seconds", or "61" to "1 minute 1 second", try the Duration class.

http://aidan.dotgeek.org/lib/?file=Duration.php
adam at roomvoter dot com
01-May-2004 10:42
The snippet of code earlier that allows you to delete all files older than 2 weeks uses the function (filemtime) - which checks the original create date of the file (filesystem independent).  You MAY want to use filectime() - that looks at when the file was last changed on YOUR file system.

       if (is_dir("$path") )
       {
           $handle=opendir($path);
           while (false!==($file = readdir($handle))) {
               if ($file != "." && $file != "..") { 
                   $Diff = (time() - filectime("$path/$file"))/60/60/24;
                   if ($Diff > 14) unlink("$path/$file");

               }
           }
           closedir($handle);
       }
wookie at at no-way dot org
14-Sep-2003 11:17
Another little handy tool; to get the most recent modified time from files in a directory. It even does recursive directories if you set the $doRecursive param to true. Based on a file/directory list function I saw somewhere on this site. ;)

function mostRecentModifiedFileTime($dirName,$doRecursive) {
   $d = dir($dirName);
   $lastModified = 0;
   while($entry = $d->read()) {
       if ($entry != "." && $entry != "..") {
           if (!is_dir($dirName."/".$entry)) {
               $currentModified = filemtime($dirName."/".$entry);
           } else if ($doRecursive && is_dir($dirName."/".$entry)) {
               $currentModified = mostRecentModifiedFileTime($dirName."/".$entry,true);
           }
           if ($currentModified > $lastModified){
               $lastModified = $currentModified;
           }
       }
   }
   $d->close();
   return $lastModified;
}
paranoid at dds dot nl
05-Jun-2003 02:43
To get the last modification time of a directory, you can use this:

<pre>
$getLastModDir = filemtime("/path/to/directory/.");
</pre>

Take note on the last dot which is needed to see the directory as a file and to actually get a last modification date of it.

This comes in handy when you want just one 'last updated' message on the frontpage of your website and still taking all files of your website into account.

Regards,
Frank Keijzers
laurent dot pireyn at wanadoo dot be
27-Sep-2001 02:00
If you use filemtime with a symbolic link, you will get the modification time of the file actually linked to. To get informations about the link self, use lstat.
24-Aug-2001 04:08
When using this function to get the modified date of a directory, it returns the date of the file in that directory that was last modified.
jay at fudge dot org
29-Jun-1999 10:55
If you want this functionality for the parent web page you should use getlastmod()
i.e.
<?php echo "Last modified: ".date( "F d Y H:i:s.", getlastmod() ); ?>
within the included page... i.e. as a commont footer include for all pages
gerardj at home dot com
20-May-1999 05:27
The above code works fine if you place it on each page you want a date stamp on.  I've found that if you place a reference such as filemtime(__FILE__) in an included or required file, that the modification time of the inherited file will be returned, not the time of the file that did the ineriting.

<fileinodefileowner>
 Last updated: Tue, 16 Nov 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2004 The PHP Group
All rights reserved.
This mirror generously provided by: nexen.net
Last updated: Fri Nov 26 05:15:47 2004 CET