php to check age of a file

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
RICKYJ
Forum Newbie
Posts: 15
Joined: Sun Nov 05, 2006 9:10 am

php to check age of a file

Post by RICKYJ »

does anyone know how i can use php to check the age of a file

I have simple bit of code that downloads rss feed to my local host, but I only want it to run if
1. the downloaded file doesnt exist
2. the downloaded file is more than say 2 hours old
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I don't know of a function to check creation time, but last modification time can be accessed using

Code: Select all

filemtime()
, if a file exists use

Code: Select all

file_exists()
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post by amir »

What operating system you are using?

If Linux / Unix, then
information can not be get. The kernel only stores three different times:
atime
Time of last access as seconds since Epoch

mtime
Time of last modification as seconds since Epoch

ctime
Time of last change as seconds since Epoch

man stat or see /usr/include/linux/stat.h
RICKYJ
Forum Newbie
Posts: 15
Joined: Sun Nov 05, 2006 9:10 am

Post by RICKYJ »

Thanks JAY that helped :D
possibly unix, but mtime seemed to work for me

I used :

Code: Select all

if ( (date('h') - date('h', filemtime("TempRSSFeed.txt")) ) > x) { // then do code
all seems to work, obviously this wont work very well if ppl only use it once every 24hrs (difference will be 0), but expect the page to be looked at at least once every few hours.

Is there a way around since i want to release this as free ware (im new to php), eg convert date to absolute seconds
Post Reply