Using some directory like temporary

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
irfan798
Forum Newbie
Posts: 11
Joined: Tue Jul 15, 2008 3:45 am
Location: Turkey

Using some directory like temporary

Post by irfan798 »

You can use it to any directory you want

Here my script

Code: Select all

<html>
<head>
<meta http-equiv='refresh' content='180'>
</head>
<body>
<?php
 
///////////////
$minutes = '15';  ///Minute that delete file if this minute past its last modify
$dir_name="/opt/lampp/htdocs/try/tmp"; ///dir name you want to use like temp !and dont but "/" to end!
//////////////
 
$dir = opendir($dir_name);
while ( gettype ( $filename2 = readdir($dir)) != boolean )
{
    $filename=$dir_name."/".$filename2;
    if (is_dir($filename)) {continue;}
       
echo "$filename was change: " . date ("i", filemtime($filename))."<br>"; ///You can delete this line
echo "And now: ".date ("i")."<br>"; ///You can delete this line
        if(date("i")-date("i", filemtime($filename)) >= $minutes or date("i") < date("i", filemtime($filename)))
        {
            if(unlink($filename)){echo $filename." deleted<br>";} else {echo "There is some eror and ".$filename." could not be deleted!";}
        }
 
}
 
?>
</body>
</html>
You can change <meta http-equiv='refresh' content='180'> 180 to what second you want the script work. Its looping

While its open any browser you can use some dir like tmp.

If you have any questions please ask..
Post Reply