Hey, anyone know how to (if it’s possible, that is) open a directory, check the creation date/time of every file in that directory and if a file is older than 24 hours, delete it.
Essentially what I’m trying to do is:
I’m trying to sell a digital download. I have a script that processes a pay pal payment, and when the payment goes through, it make a copy of a file on my server to another directory on my server that is chmod 777’ed and randomly renames it, therefore providing each purchaser / downloader with a unique download link. It was suggested to me that the easiest way to clear this temp directory is to use a cron job to clear the directory (with a php script) every 24 hours.
But the problem I have with this is that it means one downloader who purchased at the beginning of a new day would have 24 hrs to grab their file, while someone who had purchased nearer the end of the day may only have minutes.
Therefore I’m wondering is there anyway of checking the creation date / time of each file in the directory and comparing it to the server time (at time of the script running), and if the difference between the two is more than 24 hours, clear that file from the directory. But, any files where the difference is less than 24 hrs, just ignore it.
Any help would be greatly appreciated.