开发者

How to delete files of a directory in a web server periodically?

开发者 https://www.devze.com 2023-03-27 17:54 出处:网络
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 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 p开发者_JAVA技巧lease answer in detail.

I tried browsing all the answers in stackoverflow website I didn't find any questions answering my problem.


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.


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 {} \;
0

精彩评论

暂无评论...
验证码 换一张
取 消