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.
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.
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.)
the stat function (http://php.net/manual/en/function.stat.php) should do what you need.
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.