How 2 set auto delet file in directory in x minut

Started on the old forum in March 2012 · view the original in the archive · old links redirect here

8 replies · 502 views · started 14 years ago · 1 min read

5 participants
amylee Principal · 1,092 posts #2
   $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);
          }
        }
    }
  }

try that

PranaY4U Developer · 80 posts #3

amylee wrote:

   $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);
          }
        }
    }
  }

try that

where i put dis?

amylee Principal · 1,092 posts #4

you asked how to do it and that's how its done

you havn't said what type of script you are using, what files you want removing how do you expect anyone to help without any information

i have shown you a way to do it now try figuring it out

PranaY4U Developer · 80 posts #5

amylee wrote: you asked how to do it and that's how its done

you havn't said what type of script you are using, what files you want removing how do you expect anyone to help without any information

i have shown you a way to do it now try figuring it out

i want delet my mp3 files in subderectory how to set dis script?

arnage Lead · 811 posts #6

PranaY4U wrote: where i put dis?

PranaY4U wrote: i want delet my mp3 files in subderectory how to set dis script?

In the script.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
just_m3. Developer · 199 posts #7

arnage wrote: In the script.

head shot ! 🤣 your favorit kind' of user 😀 enjoy !

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

arnage Lead · 811 posts #8

God no, it isn't. 🙂 And i haven't at least enjoy it. I was serious.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
something else Fellow · 2,296 posts #9

if you are deleting files that are not in the same directory as the script on some servers you will need to use chdir() eg:

$old = getcwd();
chdir("images");
unlink("something.else");
chdir($old);

if i can show you an approved code i edit it, you dont need loads of posts from me 😛

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