gstricklind
gstricklind

Reputation: 484

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!

Upvotes: 4

Views: 6106

Answers (1)

plasmid87
plasmid87

Reputation: 1471

The __FILE__ magic constant should help you out here.

$last_modified = filemtime(__FILE__);

Upvotes: 8

Related Questions