4

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!

gstricklind
  • 464
  • 2
  • 6
  • 17

1 Answers1

8

The __FILE__ magic constant should help you out here.

$last_modified = filemtime(__FILE__);

plasmid87
  • 1,450
  • 1
  • 14
  • 20
  • 1
    Also, if you are performing multiple filesystem operations on the script during its execution (perhaps prior to `filemtime()`), I strongly recommend implementing [clearstatcache()](http://php.net/manual/en/function.clearstatcache.php). – plasmid87 Dec 20 '12 at 22:32
  • Ugh. I tried that, but didn't have the correct syntax. Works now! And thanks very much for the recommendation - I'll check it out. – gstricklind Dec 20 '12 at 22:36