0

i think this question was asked few times, which I have went through and was using some of the code from the net. Right now Im encountering problem with the time.

Let me furnish the code first:

<?php
   $pathToDir = getcwd();               

   $pathToFilesDir = $pathToDir . '\files';

   $pathToFiles = $pathToFilesDir . '\\';

    if ($handle = opendir($pathToFilesDir)) {

        while (false !== ($file = readdir($handle))) { 

            $filelastmodified = filemtime($file);

            if ($file != '.' && $file != '..'){               

                if((time() - $filelastmodified) > 60 && is_file($file)){

                    unlink($pathToFiles . $file);

                }                
            }                 
        }
        closedir($handle); 
    }

?>

This was what I was trying, to auto delete the files which are one minute older. Just for testing purposes I was trying for one minute. The result is that the files dont get deleted. On the other hand I just removed this timing condition

if((time() - $filelastmodified) > 60 && is_file($file))

and ran the script, which could delete the files immediately.

Can any one spot the mistake which I am making?

Thanks Raaks

4

1 に答える 1

0

ここで私のコードは、有効期間ごとにキャッシュをチェックします。正常に動作します。

if (is_file($dir.$file) && is_readable($dir)) {
    if ($lifetime) {
        @clearstatcache();
        if ((time() - @filemtime($dir.$file)) < $lifetime) {
            return file_get_contents($dir.$file); # Return the cache
        } else {
            @unlink($dir.$file); # Cache has expired
        }
    } else {
        return file_get_contents($dir.$file); # Return the cache
    }
} return null; # Cache not found
于 2012-06-07T15:02:10.133 に答える