Jump to content

Deletes all files


brentmoeller

Recommended Posts

when the blow code is ran it produces this warning error

 

Warning: filemtime() [function.filemtime]: stat failed for 048_Baby_Colors.png in /home/public_html/.com/kill.php on line 23

 

 

The code deletes all the files in the directory no matter how many hours or seconds ago they was last modified. could someone help me figure out why?

<?php

$dir = '/home/br/public_html/l.com/dfile';

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


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

        if ($file[0] == '.' || is_dir("$dir/$file")) {


            continue;

        }

        if ((time() - filemtime($file)) > ($days * 604800)) {

            unlink("$dir/$file");

        }

    }

    closedir($handle);

}

?>

Link to comment
https://forums.phpfreaks.com/topic/228905-deletes-all-files/
Share on other sites

Warning: filemtime() [function.filemtime]: stat failed for 048_Baby_Colors.png in /home/public_html/.com/kill.php on line 23

 

This seems to indicate that the system could not find the file that you passed to filemtime(). Since it also shows the filename it was looking for, you can see that there is no directory path specified in the value passed to filemtime(). I think you need to add the directory you are searching to that call:

 

filemtime($dir . '/' . $file)

Link to comment
https://forums.phpfreaks.com/topic/228905-deletes-all-files/#findComment-1180050
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.