Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get last modified file time dynamically

Tags:

php

filemtime

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!

like image 800
gstricklind Avatar asked Feb 18 '23 02:02

gstricklind


1 Answers

The __FILE__ magic constant should help you out here.

$last_modified = filemtime(__FILE__);

like image 107
plasmid87 Avatar answered Feb 26 '23 21:02

plasmid87