auto delete files more than 50 days

Started on the old forum in June 2013 · view the original in the archive · old links redirect here

7 replies · 1,070 views · started 13 years ago · 1 min read

6 participants
Busary Junior · 14 posts #1

help everyone!.i want a php script that auto delete files more than 50 days on my website.thanks

djdevil89 Senior · 287 posts #3

have a sql with the uploaded date, then use php cli to check the uploaded file against the current date, if it is older then 50 days unlink the file and remove the sql entry

foreach ($_SERVER as $server => $value)
{
echo "$server is $value<br />";
}
arnage Lead · 811 posts #4

By amylee:

$path = dirname(__FILE__).'/files'; 
  if ($handle = opendir($path)) { 

    while (false !== ($file = readdir($handle))) { 
        if ((time()-filectime($path.'/'.$file)) < 86400) {  // auto-deletion every 24 hours 
          if (strripos($file, '.txt') !== false) { //deletes particular file extension 
            unlink($path.'/'.$file); 
          } 
        } 
    } 
  } 
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
charith7788 Developer · 51 posts #5

Use cron job with a command included php file

Busary Junior · 14 posts #6

arnage wrote: By amylee:

$path = dirname(__FILE__).'/files'; 
  if ($handle = opendir($path)) { 

    while (false !== ($file = readdir($handle))) { 
        if ((time()-filectime($path.'/'.$file)) < 86400) {  // auto-deletion every 24 hours 
          if (strripos($file, '.txt') !== false) { //deletes particular file extension 
            unlink($path.'/'.$file); 
          } 
        } 
    } 
  } 

Thanks guys..seems cron job is simpler,bt i stil find this code useful..thanks

wap2k Developer · 168 posts #7

4320000 seconds in 50 days to modify the date function above.

charith7788 Developer · 51 posts #8

Busary wrote: Thanks guys..seems cron job is simpler,bt i stil find this code useful..thanks

make a new cron job as like get delete.php (delete.php is the file which include the code)

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close