Skip to content

Instantly share code, notes, and snippets.

@tureki
Created February 20, 2014 08:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tureki/9109489 to your computer and use it in GitHub Desktop.
Save tureki/9109489 to your computer and use it in GitHub Desktop.
php get last modified file in folder
<?php
$str_path = '/PATH/';
$cls_rii = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator( $str_path ),
\RecursiveIteratorIterator::CHILD_FIRST
);
$ary_files = array();
foreach ( $cls_rii as $str_fullfilename => $cls_spl ) {
if($cls_spl->isFile())
{
$ary_files[] = $str_fullfilename;
}
}
$ary_files = array_combine(
$ary_files,
array_map( "filemtime", $ary_files )
);
arsort( $ary_files );
$str_latest_file = key( $ary_files );
echo "file:".$str_latest_file."\n";
echo "time:".$ary_files[key( $ary_files )];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment