Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save goesredy/ec168ff8e37face2184931684d630ab7 to your computer and use it in GitHub Desktop.

Select an option

Save goesredy/ec168ff8e37face2184931684d630ab7 to your computer and use it in GitHub Desktop.

Revisions

  1. @tureki tureki created this gist Feb 20, 2014.
    33 changes: 33 additions & 0 deletions php-get-last-modified-file-in-folder.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    <?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 )];

    ?>