I'm looking to setup a cronjob in order to automatically delete files within a certain directory 24 hours after it's been uploaded. I've seen some tutorials on this, but I'm misunderstanding what they're saying and I don't want to mess anything up. Here is what I'm seeing: In order to delete a file that's been created 24 hours ago, what should the time settings be? I believe this is the command that I should put, but can someone verify this please? find /path/to/files -mtime +1 -exec rm {}\; Code (markup): Thank you! - Nate
You can use php to do this <?php $files = glob("/directory/you/want/to/delete/files/in/*.*"); foreach($files as $file) unlink($file); ?> Code (markup): save above as cron.php and modify directory. and in crontab 0 0 * * * /usr/local/bin/php /diretcory/where/your/cron.php minute = 0 hour = 0 day = * month=* weekday=* This will run everyday at midnight.
Thanks "st1905" for the reply. It's just that I need the file to delete exactly (or slightly around) 24 hours after it was uploaded. For instance, if a file is uploaded at 7:30PM a certain day, I want it deleted the next day at 7:30PM. I'm not sure if I can achieve that with a cronjob, though.