Jump to content


Photo

Newest File script help


  • Please log in to reply
3 replies to this topic

#1 rab

rab
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts

Posted 10 May 2006 - 08:59 PM

<?
$y = 0;

if ($handle = opendir('.'))
 {
   while (false !== ($file = readdir($handle)))
    {
       if ($file != "." && $file !=".." && $file != "_private" && $file != "_vti_bin" && $file != "_vti_cnf" && $file != "_vti_pvt" && $file != "_vti_txt" && $file != "_vti_log" && $file != "cgi-bin" && $file != ".ftpquota" && $file != ".htaccess" && $file != "sniffer")
        {
            $lastmod = date('[d-m-y//g-i-s-a]' , filemtime($file));
               
            $z[$y] = $lastmod;
            $q[$y] = $file;
            $y++;
        }
    }
   closedir($handle);
 }
 

        
sort($z);
$size = (sizeof($z) - 1);
echo $z[$size];
echo $q[$size];

?> 
This works to an extent, i can sort the date, but i can't sort the file accordingly to the date. Is there anyway to do this?



#2 rab

rab
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts

Posted 13 May 2006 - 12:47 AM

Doesn't Anyone know this?

#3 Zubaz

Zubaz
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 13 May 2006 - 12:53 AM

You need to output your date string in a manner that will sort numerically.

06042006 for June 4th 2006 won't sort like you want it to.

20060604 will sort correctly, because the heirarchy is in the same direction.


06042006 > 03042008 (wrong)

20060604 < 20080304 (right!)


After that just do something like assign to an array with the date as the key and then do a ksort.

(inside your while loop)
$filesArray[$date] = $filename;
(end while loop)


ksort($filesArray);

echo '<pre>';
print_r($filesArray);
echo '</pre>

[a href=\"http://www.php.net/ksort\" target=\"_blank\"]ksort() on php.net[/a]

#4 rab

rab
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts

Posted 13 May 2006 - 01:16 AM

OMG I forgot about keys in arrays! Thanks!<3




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users