Reputation: 3
I want to display a file upload demo in my website.
So I need to delete all the files in the uploads directory every one hour.
I am using a remotely hosted platform( linux).
I want to know how to implement this.
How to delete files of a directory in a web server periodically?
I think it can be implemented using cron job but I don't have much knowledge about cron jobs So please answer in detail.
I tried browsing all the answers in stackoverflow website I didn't find any questions answering my problem.
Upvotes: 0
Views: 1667
Reputation: 802
every 15 min and every hour and day and moth delete files *.php
15 * * * * find /domaine_path/ -mtime +7 -type f -name "*.php" -exec rm -f {} \;
Upvotes: 0
Reputation: 2613
Use crontab -e
to edit your crontab. I am assuming you have shell access to your server of course.
Then add the following line:
0 * * * * rm -f /path/to/dir/*
I believe crontab
defaults to vim
as an editor, so if you are not familiar, just remember: press i
to begin editing, then Esc
to return to command mode, followed by :wq
to write to file and quit.
If you don't have shell access to your server...then best I can think of is having PHP/whatever backend you are using check the time on every request.
Upvotes: 2