Last active
August 29, 2015 14:26
-
-
Save ryanfitton/9b23fbf0a4d0bd65f401 to your computer and use it in GitHub Desktop.
PHP Function: Get a file's last modification timestamp - PHP Function - https://ryanfitton.co.uk/blog/php-function-get-a-files-last-modified-timestamp/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Get the file's last modified timestamp | |
function lastModTimestamp($filename, $filepath = NULL, $displayV = false) { | |
//Combine filepath and filename | |
$file = $filepath . $filename; | |
//If this file exists | |
if (file_exists($file)) { | |
//Get the filename's last modified date | |
$lastModDate = date("Y-m-d", filemtime($file)); | |
//Convert the last modified date into a new Date Time object | |
$lastModTimestamp = new DateTime($lastModDate); | |
//If $displayV is not set (NULL), only return Timestamp | |
if ($displayV == false) { | |
//Format Date Time object into a Timestamp and return | |
return $lastModTimestamp->getTimestamp(); | |
//If $displayV is set as "true", return '?v=' and Timestamp | |
} elseif ($displayV == true) { | |
//Add '?v=', format Date Time object into a Timestamp and return | |
return "?v=" . $lastModTimestamp->getTimestamp(); | |
//If anything else, something is broken when checking $displayV, do not display anything | |
} else { | |
return false; | |
} | |
//If file is not found, do not display anything | |
} else { | |
return false; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment