I have a function that displays a list of all the files upload to a specific webpage. I also want to display the date that the file was last modified, but it is displaying all of the dates as December 31 1969 19:00:00. How do I amend this function so that it displays the correct date? (it's in the echo statement at the end):
<?php
foreach($phpfiles as $phpfile)
{
$imageFileType = pathinfo($phpfile,PATHINFO_EXTENSION);
if ($imageFileType == "pdf") {
$faicon = 'fa fa-file-pdf-o';
} else if ($imageFileType == "doc" || $imageFileType == "docx") {
$faicon = 'fa fa-file-word-o';
} else if ($imageFileType == "xls" || $imageFileType == "xlsx") {
$faicon = 'fa fa-file-excel-o';
} else if ($imageFileType == "ppt" || $imageFileType == "pptx") {
$faicon = 'fa fa-file-powerpoint-o';
} else if ($imageFileType == "mp4") {
$faicon = 'fa fa-file-video-o';
} else if ($imageFileType == "jpg" || $imageFileType == "png" || $imageFileType == "gif" || $imageFileType == "bmp") {
$faicon = 'fa fa-file-image-o';
} else {
$faicon = 'fa fa-file-text-o';
}
if ($server_name <> ""){
$phpfile = "http://". $server_name . '/' .$phpfile;
}
echo "<span class='$faicon w3-large'></span>  <a href='$phpfile' class='w3-medium' target='_blank'>".substr(basename($phpfile),-1*strlen(basename($phpfile))+strlen($id)+1)."</a> ". date("F d Y H:i:s.", filemtime($phpfile));
}
?>
As in comments above:
The problem is that you overwrite the variable $phpfile with this code:
if ($server_name <> ""){
$phpfile = "http://". $server_name . '/' .$phpfile;
}
If you instead create a variable with the filemtime date before you change string $phpfile then you can echo it later.
$date = date("F d Y H:i:s.", filemtime($phpfile));
if ($server_name <> ""){
$phpfile = "http://". $server_name . '/' .$phpfile;
}
echo "<span class='$faicon w3-large'></span>  <a href='$phpfile' class='w3-medium' target='_blank'>".substr(basename($phpfile),-1*strlen(basename($phpfile))+strlen($id)+1)."</a> ". $date;