note 91665 added to function.filemtime

From: Date: Mon, 22 Jun 2009 10:59:28 +0000
Subject: note 91665 added to function.filemtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-157214@lists.php.net to get a copy of this message
It could be useful to determinate the timestamp of the newest file in a directory. (e.g. if you want to find out when the last change was made to your project). Following function will help you: <?php function getAllFiles($directory, $recursive = true) { $result = array(); $handle = opendir($directory); while ($datei = readdir($handle)) { if (($datei != '.') && ($datei != '..')) { $file = $directory.$datei; if (is_dir($file)) { if ($recursive) { $result = array_merge($result, getAllFiles($file.'/')); } } else { $result[] = $file; } } } closedir($handle); return $result; } function getHighestFileTimestamp($directory, $recursive = true) { $allFiles = getAllFiles($directory, $recursive); $highestKnown = 0; foreach ($allFiles as $val) { $currentValue = filemtime($val); if ($currentValue > $highestKnown) $highestKnown = $currentValue; } return $highestKnown; } // Use example echo 'The newest file has the time stamp:<br>'; echo date('Y-m-d H:i:s', getHighestFileTimestamp('../')); ?> ---- Server IP: 212.124.37.9 Probable Submitter: 141.19.141.25 ---- Manual Page -- http://www.php.net/manual/en/function.filemtime.php Edit -- https://master.php.net/note/edit/91665 Del: integrated -- https://master.php.net/note/delete/91665/integrated Del: useless -- https://master.php.net/note/delete/91665/useless Del: bad code -- https://master.php.net/note/delete/91665/bad+code Del: spam -- https://master.php.net/note/delete/91665/spam Del: non-english -- https://master.php.net/note/delete/91665/non-english Del: in docs -- https://master.php.net/note/delete/91665/in+docs Del: other reasons-- https://master.php.net/note/delete/91665 Reject -- https://master.php.net/note/reject/91665 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157214) next »