Jump to content

How to get the time the file was last modifed at in a PHP script


APD1993

Recommended Posts

I've heard about a function that does so, but I did not have much luck implementing it. Is is possible for me to get the time my file was modified in this script?

 

<html><head>
<title>RCM File List</title>
<link rel="stylesheet" type="text/css" a href="/rcm/stylesheet.css">
</head>
<body>
<h1>Files in RCM Directory</h1>
<?php
$dir="C:/xampp/htdocs/rcm/*txt";


foreach(glob($dir) as $file)
{
$list = "<li><a href='readfile2.php'>Filename: $file</a></li><br>";
}
?>

<ul>
<?php echo $list; ?>
</ul>
</body>
</html>

Yes.

 

The function is filemtime. If you show the code you tried and any error messages, we can help you fix it. The most likely reason it failed (IMO) is that the glob function returns just the filenames (without the path portion), but you need to specify the path in the call to filemtime().

Yes.

 

The function is filemtime. If you show the code you tried and any error messages, we can help you fix it. The most likely reason it failed (IMO) is that the glob function returns just the filenames (without the path portion), but you need to specify the path in the call to filemtime().

 

I got this error message:

Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\viewfile3.php on line 13

 

When I used this code:

<html><head>
<title>RCM File List</title>
<link rel="stylesheet" type="text/css" a href="/rcm/stylesheet.css">
</head>
<body>
<h1>Files in RCM Directory</h1>
<?php
$dir="C:/xampp/htdocs/rcm/*txt";
$filename='C:/xampp/htdocs/rcm/denman2.txt';
if (file_exists($filename)) {
foreach(glob($dir) as $file)
{
$list = "<li><a href='readfile2.php'>Filename: $file</a></li><p>$filename was last changed on: " . date("F d Y H:i:s, filetime($filename));<br>";
}
}
?>

<ul>
<?php echo $list; ?>
</ul>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.