Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

php - Automatically delete files from webserver

I need to delete files from a directory in my web-server and I need some script to do it automatic. And there is few more conditions which need to be fulfilled.

  • It has to clean the directory then total file size exceeds some certain limit for example 1,5GB
  • That files would be deleted every 24 hours.
  • New files like 10 ir 20 mins old would not be deleted
  • It would be just awesome if all of the conditions above would be work at the same time.

For deleting files I was thinking of some kind of corn task but I do not know a thing about them so it is tricky for me.
To delete files then a certain limit is reached I was thinking that some kind of PHP script my help. May be there is a library meant for these things.
Any way I will be very happy for any kind of help. May be I just need some fresh thoughts to come up with a right keyword for google ;P

EDIT: My server runs on linux.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If your server is running linux, a cron job is the best option. Simply write a script that checks the conditions you mention (using e.g. stat and some other tools) and deletes the file if they apply, and set crond to run it every 24 hours. Here's a short introduction to cron.

On Windows, you'd do something similar with a script and a scheduled task.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...