Hi guys, Im a newb here, so bear with me! Still learning the ropes. I want to delete all files from my server that are 6 hours old since being uploaded to the site. I believe i need a cron job? I currently have this script in its framework... Cannot post the code here yet for some reason: but its last post here /showthread.php?t=1849721 Would that work automatically or would it need a cron to run it? And how could i test it, that bit worries me. Many thanks.
You shurly need a cronjob. Most providers/hosters will have a control panel where you can add a cronjob. Maby contact your hosting provider?
If you are using a hosting that provides cPanel then you can easily set up cron jobs just google some tutorials on how to setup and use cron jobs
Another way that would be ignorant but fun, would be to make a looping AJAX div table with a looping PHP handler that loads, gets the time, and then has it reload,therefore restarting the script /handler .. and compares the time to the set time to erase that starts when you activate it with a button and when at 0 time left it runs a PHP script that deletes all files and folders in the name list of files/folders. last but not least erasing all text from the file of the handler itself..leaving maybe the first line on the text with // All Files Successfully Destroyed , Mr Bond.
The script in post 5 would do it, but I'd change if ($difference == $x) { unlink($file_name); to if ($difference >= $x) { unlink($file_name); With the first one, if the script doesn't run within that minute, the file doesn't get deleted. And change $x = 30; to $x = 360; (6 hours). You definitely want a cron job. Running a looping program will eat much too much CPU time.