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>

Link to comment
Share on other sites

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().

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.