hello, can anyone please help me. i have my own vps and whm/cpanel etc. on my site i want automatically that folders older then 50 days gets deleted. how can i set this? script/code? can anyone please help. i want the entire folder gets deleted with the files in it, automatically if a folder is older then 50 days.
I did not test it but should work just fine. and will delete sub folders of current dir alternatively you can supply dir path as first argument to glob function call. $dirs = glob('*', GLOB_ONLYDIR); $fifty_days = (24*3600 /*1 day */) * 50; foreach ($dirs as $dir) { if (filectime($dir) <= time() - $fifty_days) `rm -rf $dir`; } Code (markup): stay well
can you please tell me exactly how and where i need to put this code? i am a noob at coding, please help me
you put this in a file such as script.php you run the script by using a cron job. google cron jobs on how to do this. I havent tested the above code, so no comments on if it will work, however as you say you are a noob, you need to know that you will need to put at the start of the file <?php and at the end of the file ?>
ok, i have a folder called 'week2' i want to let this delete after x days so in this folder i put a php file with the above code in it. and this code i recall it every day with a cronjob? and this code look if the folder is older then x days, it will remove? folder is called week2, so how to put week2 in this code? where?
You've to put the script in the parent directory of week2. And you don't have to call it 'every day', it will run automatically once you set up a cron job. No need to put week2 anywhere in the code.