[Solved] Any way to delete a file after inactivity?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Jeefo
Forum Newbie
Posts: 16
Joined: Thu Jun 16, 2005 3:38 pm
Location: Tokyo, Japan

[Solved] Any way to delete a file after inactivity?

Post by Jeefo »

Well, let me make this more clear. I have a website where people can upload their files. In the FAQ it explains that files are deleted after 30 days of inactivity (unless they re-upload the file). Well is there a script I can use to delete the file automatically? Thanks in advance.
Last edited by Jeefo on Thu Aug 25, 2005 5:15 pm, edited 1 time in total.
programmermatt
Forum Commoner
Posts: 65
Joined: Tue Mar 15, 2005 5:03 pm
Contact:

Post by programmermatt »

Do you mean if the user is inactive for 30 days? Or do you mean if the file is not accessed for 30 days?
User avatar
Jeefo
Forum Newbie
Posts: 16
Joined: Thu Jun 16, 2005 3:38 pm
Location: Tokyo, Japan

Post by Jeefo »

programmermatt wrote:Or do you mean if the file is not accessed for 30 days?
Something like that...this is taken from the FAQ:

"Q: Will my files ever be deleted?
A: They will be deleted 30 days after you upload. To keep the file before the 30 days is up, just upload the same one(s) again and check "Overwrite". They will also be deleted immediatly if it is x-rated or if it promotes any illegal activities."
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Run a daily cron job that reads the files. If the timestamp is older than 30 days, get rid of it.
User avatar
Jeefo
Forum Newbie
Posts: 16
Joined: Thu Jun 16, 2005 3:38 pm
Location: Tokyo, Japan

Post by Jeefo »

Skara wrote:Run a daily cron job that reads the files. If the timestamp is older than 30 days, get rid of it.
Thanks for your help, but I am *very* new to PHP. Could you tell me (or supply a webpage) about cron jobs and timestamps?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I would'nt use php for that at all... Little shell script would look like (untested, it has been ages that i wrote bash)

Code: Select all

#!/bin/sh
for file in `find /var/www/uploads`
do
  if ї -f &quote;$file&quote; ]
  then
    stat=`stat &quote;$file&quote;`
    if (( $stat > 30 * 24 * 60 * 60 ))
    then
      `rm &quote;$file&quote;`
    fi
  fi
done
More info about a crontab you can find at your local websearch engine...
Post Reply