Forum Moderators: coopster

Message Too Old, No Replies

Ooooo, Time travel

problem with filemtime

         

benry

2:02 am on Sep 17, 2005 (gmt 0)

10+ Year Member



Heh everyone.
I wonder if the collective could help with a wee problem.
I am trying to sort a number of directories by date order using filemtime but am stuck in Disco land - every file comes back saying it was last modified on Jan 1, 1970 (hmmm, nice trousers...).
Clearly I am doing something catatonically stupid but, er, I can't see what it is.

Here is the main bit of the problem code - it reads the contents of four directories (controlled by $section) into a multi-dimensional array (at least it is supposed to)...

if (is_dir($dir))
{

// can it be opened?
if ($dh = opendir ($dir))
{

// don't load any file beginning with '.'
while (false!== ($file = readdir ($dh)))
{

if (strpos ($file,'.')>0)
{

// get the last modified time
$LastModified =date ("ymdHis", filemtime($file));

// debug line
echo "section = $section: file = $file :last mod = $LastModified <br />";

// if there is a mod time then store this
if ($LastModified)

{
$files [$section][$LastModified] = array ($file);

// sort these by last modified
ksort ($files [$section]);
}
}
}

// close the file
closedir ($dh);
}

it returns with every file last mod= 700101010000

I have tried fileatime, mtime and ctime - with the same result.

Hope someone can help.

Many, many thanks.

coopster

5:32 pm on Sep 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Before you get the filemtime of $file, print $file to the screen to see what value it holds. It appears you aren't offering the full path to the filemtime function. Try modifying that line if this is the case.
filemtime("$dir/$filename")

benry

9:26 am on Sep 19, 2005 (gmt 0)

10+ Year Member



We are not worthy ...

Very many thanks indeed . Hit the nail bang on the head. Hugely appreciative of your help.

Ben