Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to clean a directory using PHP after a certain amount of days? I'd like to put the amount of days into a $Cleanup variable? I've tried and not been able to get it working.

share|improve this question

You would need to set a cron job (scheduled task) you set these via the server control panel or with ssh to the server.

You would basically make a script that contained the code to delete all items in the directory and tell the cron task the path of that script, then tell it to run periodically.

share|improve this answer
What script would I need to add to delete files after 14 days? – Iestyn Oct 1 '13 at 23:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.