PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
on my site i have a flat-file counter system for a section of games, it just stored the 3bytes of info needed for game played "223" times, you get the idea.
what i would like to do is create a script that finds which counter file was last modified (written too), so that i could say
"$game was last played ....."
except i have not very much idea how to do this, lol, i know you can find out the filemtime thing but i dunno how to work that on a file that your not running it from....
So what I think is the best approach is to simply iterate through the directory that contains all the counter files... if you don't have this, possibly consider either a different organization or create links to each file in a single directory.
Now $last_changed will always equal the last file that was modified. (plus you can get the unix time stamp if you wanted too for when it was accessed. Using the date function you could nicely format that)
http://www.zerodegreeburn.com/games.php
(Games - The last game played was Space Invaders)
obviously what would be fun to add was
(Games - The last game played was Space Invaders on Wed 24 10:26:23)
.... i feel stuuupid, i been looking around at file last modified but i still dont get how to do it on a file that your not directly ON.
filemtime() returns a Unix timestamp. To format that timestamp you can use date() like you had in your post, just with $last_changed_time as the second argument:
Ah. OK. That's what I get for posting code I haven't tested. It looks like you'll need to initialize the $oldest_time variable so that the first file encountered will immediately be older than the time stored in $oldest_time. Try adding:
before the "while" loop. That way, the very first file through the loop (at least) should be older than $oldest_time and it should go into that if clause.
It looks like you also have a typo in your last "echo"statement. There is an extra "l" in your variable name. No big deal.