Page 1 of 1

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

Posted: Sun Jun 19, 2005 10:22 pm
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.

Posted: Sun Jun 19, 2005 10:25 pm
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?

Posted: Sun Jun 19, 2005 10:27 pm
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."

Posted: Sun Jun 19, 2005 11:03 pm
by Skara
Run a daily cron job that reads the files. If the timestamp is older than 30 days, get rid of it.

Posted: Sun Jun 19, 2005 11:05 pm
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?

Posted: Mon Jun 20, 2005 2:49 am
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...