views:

41

answers:

3

hi all,

I am making a crone file which will detect the file uploaded before 24 hrs and delete them. I want to know how can I detect the time of file uploaded, So i can calculate it's uploaded time and delete it.

+2  A: 

PHP has filemtime().

// check if the file is at least 1 day old.
if (time() - filemtime($filename) > 86400) ...

Or you could do it via a shell script. Example:

# delete all files older than 1 day
find /upload/directory -mmin +1440 -print | xargs ls

# delete all jpg files older than 1 day
find /upload/directory -name "*.jpg" -mmin +1440 -print | xargs ls

(Replace ls with rm when you feel comfortable deleting all of those files.)

konforce
A: 

the stat function (http://php.net/manual/en/function.stat.php) should do what you need.

Yuliy
Hi, state function is also work but i tried filemtime() first. State function returns an array of file attributes. In that array 8th element denote last-Access-Time for file, but filemtime() directly return the last-Access-Time.thnx
Naresh
A: 

If you explore the SPLFileInfo class, you can do all kinds of nifty stuff. You want to look at SPLFileInfo::getMTime. If you compare it against the current time minus 24 hours, you can easily figure out which files you should unlink. These are all OS independent.

CaseySoftware