RE: [PHP] "last modified" code not working on new server :-(
| From: | Martin Towell | Date: | Tue, 18 Jun 2002 06:32:19 +0000 |
| Subject: | RE: [PHP] "last modified" code not working on new server :-( | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-102654@lists.php.net to get a copy of this message | ||
first time through the loop, $newFile is set to "" - so you're trying to
stat a file called ""
I dunno why it worked on your old server - maybe you have a different error
reporting level ??
put a check in to see if $newFile != "" and change the if ($newDate <
$fileDate) { line to suit too
-----Original Message-----
From: Timothy J. Luoma [mailto:luomat@peak.org]
Sent: Tuesday, June 18, 2002 4:26 PM
To: PHP Mailing List
Subject: [PHP] "last modified" code not working on new server :-(
Summary: A working piece of PHP code is not working once moved to a new
server.
Details:
1) Old server running PHP/4.0.6 vs New server running PHP/4.1.2 (*)
2) Error message received is:
Warning: stat failed for (errno=2 - No such file or directory) in
/www/global/php/lastmodified.php on line 10
3) line 10 is:
$newDate = filemtime($newFile); // get date from newFile
4) The whole code is below for review. The code in question is supposed
to return the most-recently modified file in a directory (this was found
at the PHP.net site)
<?php
// last update
$newFile=""; // init newFile
$handle=opendir('.'); // open dir
while (false!==($file = readdir($handle))) { // read all files in dir
if ($file != "." && $file != "..") { //only if file is not . or
..
$fileDate = filemtime($file); // get date from file
$newDate = filemtime($newFile); // get date from newFile
if ($newDate < $fileDate) { // if file is newer
$newFile = $file; // replace newFile with newer
file
}
}
}
closedir($handle); // close file
$newDate = filemtime($newFile); // get date from newFile
$fileModDate = date("d/m/Y",$newDate); // convert date
Print("updated: $fileModDate"); // print date
?>
(Is PHP/4.1.2 secure? I know it's not the newest)
Any clues why this isn't working?
Thanks
TjL, PHP neophyte
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php