Page 1 of 1

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

Posted: Fri Sep 22, 2006 1:29 pm
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 :)

Posted: Fri Sep 22, 2006 1:34 pm
by feyd
You'll use filemtime(), time() and a bit of math.

Oh, and unlink().

Posted: Fri Sep 22, 2006 2:37 pm
by DARKGuy2008
Hehe, I guess I can do with that, thanks a lot :)