Search code examples
phpfilemtime

Get last modified file time dynamically


I've made a few unsuccessful attempts. I want to get the last modified file time, by current file - i.e. the file currently being viewed. The following code works for the employer.es.php file, but I reuse this in other files unless I keep changing the file names.

    <?php
    // make var from file name
    $last_modified = filemtime("employer.es.php");
    // print date
    echo "Information last modified on " . date("m/d/Y", $last_modified);
    ?> 

So instead of having to type the files name into each file, I want it to use the current file. Hope I'm making sense :/ Thank you!


Solution

  • The __FILE__ magic constant should help you out here.

    $last_modified = filemtime(__FILE__);