APD1993 Posted March 3, 2012 Share Posted March 3, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/258199-how-to-get-the-time-the-file-was-last-modifed-at-in-a-php-script/ Share on other sites More sharing options...
SergeiSS Posted March 3, 2012 Share Posted March 3, 2012 This might help you: http://ru2.php.net/manual/en/class.directoryiterator.php Look for DirectoryIterator::getMTime Quote Link to comment https://forums.phpfreaks.com/topic/258199-how-to-get-the-time-the-file-was-last-modifed-at-in-a-php-script/#findComment-1323536 Share on other sites More sharing options...
DavidAM Posted March 3, 2012 Share Posted March 3, 2012 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(). Quote Link to comment https://forums.phpfreaks.com/topic/258199-how-to-get-the-time-the-file-was-last-modifed-at-in-a-php-script/#findComment-1323538 Share on other sites More sharing options...
APD1993 Posted March 3, 2012 Author Share Posted March 3, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/258199-how-to-get-the-time-the-file-was-last-modifed-at-in-a-php-script/#findComment-1323542 Share on other sites More sharing options...
APD1993 Posted March 4, 2012 Author Share Posted March 4, 2012 Does anyone know how to try to fix this error? Quote Link to comment https://forums.phpfreaks.com/topic/258199-how-to-get-the-time-the-file-was-last-modifed-at-in-a-php-script/#findComment-1323713 Share on other sites More sharing options...
kicken Posted March 4, 2012 Share Posted March 4, 2012 Look at the highlighting in your previous post. Your missing a double-quote. Quote Link to comment https://forums.phpfreaks.com/topic/258199-how-to-get-the-time-the-file-was-last-modifed-at-in-a-php-script/#findComment-1323718 Share on other sites More sharing options...
litebearer Posted March 4, 2012 Share Posted March 4, 2012 Also, as DavidAM said, its filemtime not filetime NOTICE the 'm' between file and time. It generates the timestamp Quote Link to comment https://forums.phpfreaks.com/topic/258199-how-to-get-the-time-the-file-was-last-modifed-at-in-a-php-script/#findComment-1323730 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.