Getting a file's date and deleting it if it's too old?

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!

Moderator: General Moderators

Post Reply
DARKGuy2008
Forum Newbie
Posts: 2
Joined: Fri Sep 22, 2006 1:20 pm

Getting a file's date and deleting it if it's too old?

Post by DARKGuy2008 »

Greetings!

I'm wondering how would I get a file's date (as in, knowing how many hours old it is) and being able to do a comparison and delete it if true. Say, a file in my server should last only 24 hours (it's for a test I'm doing), if it gets older, it gets deleted. So, how would I go into knowing how many hours old the file is, and to know when it's greater than 24?

Thanks in advance :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You'll use filemtime(), time() and a bit of math.

Oh, and unlink().
DARKGuy2008
Forum Newbie
Posts: 2
Joined: Fri Sep 22, 2006 1:20 pm

Post by DARKGuy2008 »

Hehe, I guess I can do with that, thanks a lot :)
Post Reply