Frage

I am basically trying to only return files less than 1 day. The posts on here contain deleting files older than X days. I wish to return files that are less than 1 day. I figured it would be as simple as adding filemtime but it doesn't seem to be working.

function dirList ($directory){
   $results = array();
    $handler = opendir($directory);

    while ($file = readdir($handler)) {

        if ($file != '.' && $file != '..')
            $results[] = $file;
    }
    closedir($handler);
    return $results; }

I have tried playing with filemtime and adding it to:

    if ($file != '.' && $file != '..' && filemtime($file) < time() - 86400)
            $results[] = $file;

This just displays everything still.

    if ($file != '.' && $file != '..' && filemtime($file) > time() - 86400)
            $results[] = $file;

Displays nothing.

War es hilfreich?

Lösung

$file is a filename relative to $directory, but filemtime will interpret it relative to the process's current directory. You need to give correct pathname to filenmtime:

filemtime($directory . '/' . $file)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top