mtime: modified time


/ Published in: PHP
Save to your folder(s)

Get modified time of a directory or file. For directories: it gets the modified time of the most recently modified file.


Copy this code and paste it in your HTML
  1. /**
  2.  * mtime() Get the modified time of a directory or file. For directories,
  3.  * it gets the modified time of the most recently modified file.
  4.  *
  5.  * @param string $path Full path to directory or file.
  6.  * @param string $format Date string for use with date()
  7.  * @return number|string|null
  8.  */
  9. function mtime ( $path, $format = null ) {
  10. $time = null;
  11. if ( \is_string($path) && \is_readable($path) ) {
  12. if ( \is_dir($path) ) {
  13. $path = \rtrim($path, '/');
  14. foreach ( \scandir($path) as $file ) {
  15. if ( '.' !== \substr($file, 0, 1) ) {
  16. $temp = mtime($path . '/' . $file);
  17. $temp > $time and $time = $temp;
  18. }
  19. }
  20. } elseif ( \file_exists($path) ) {
  21. $time = \filemtime($path);
  22. }
  23. }
  24. return $time && $format ? \date($format, $time) : $time;
  25. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.