john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

filetime

<?php
    // 2011-06 johnpfeiffer sort by filename or filename last modified timestamp

function displayFileInformation( $filename , $filelastmodifiedtimestamp )
{
    if( !is_null( $filename ) && !is_null( $filelastmodifiedtimestamp ) )
    {
        print "<tr>";
        print "<td>" . $filename . "</td>";
        print "<td>" . $filelastmodifiedtimestamp . "</td>";
        print "<td>" . date( "Y-m-d H:s T", $filelastmodifiedtimestamp ) . "</td>";
        print "</tr>\n";
    }
} //end displayFileInformation()


    date_default_timezone_set('UTC');
  clearstatcache();
    $currentdirectory = getcwd();
    $currentydirectoryhandle = opendir( $currentdirectory );

    if( $currentydirectoryhandle )
    {
    $filename = readdir( $currentydirectoryhandle );

    while( $filename !== false )
    {
      if( $filename != "." && $filename != ".." && is_file($filename) )
      {
//          $filelastmodifiedtimestamp = filectime( $filename );
        $filelastmodifiedtimestamp = filemtime( $filename );
        $filelist[] = array( "name" => $filename, "lastmodifiedtimestamp" => $filelastmodifiedtimestamp );
      }
      else
      {   $dirlist[] = $filename;
      }

      $filename = readdir( $currentydirectoryhandle );
    }

    closedir( $currentydirectoryhandle );
    } //end if


    print "<table>\n";

    foreach( $dirlist as $key => $value )
    {
        displayFileInformation( $value , filemtime( $value ) );
    }
    displayFileInformation( " " , 0 );


    foreach( $filelist as $key => $value )
    {
        displayFileInformation( $filelist[ $key ]['name'] , $filelist[ $key ]['lastmodifiedtimestamp'] );
    }

    print "</table>";
    include( $_SERVER["DOCUMENT_ROOT"] . "/includes/foot.txt");

    /*
    FUTURE RESEARCH & NOTES:

    $path = $_SERVER['PHP_SELF'];
    $base = basename($path);
    $last_modified = filemtime( $base );

    "last modified: " . date("l, dS F, Y", getlastmod() ) . "<br />\n";
    http://www.php.net/manual/en/function.stat.php
    */
?>

  • « interface inheritance example
  • php filetime continued »

Published

Jun 12, 2011

Category

php

~138 words

Tags

  • filetime 4
  • php 82