Forked from tureki/php-get-last-modified-file-in-folder.php
Created
January 31, 2023 18:06
-
-
Save goesredy/ec168ff8e37face2184931684d630ab7 to your computer and use it in GitHub Desktop.
php get last modified file in folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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