[Wolves] Problem with code

Mike Peters mike at ice2o.com
Fri Feb 18 15:59:27 GMT 2005


On Fri, 18 Feb 2005 14:57:17 +0000
Wayne Morris <wayne at machx.co.uk> wrote:

> Sorry if there has been any replies to this but my mailserver lost 36 
> messages yesterday.
> Please repost any replies please.
> 
> Can someone interpret this code for me - on my old server it correctly
> displayed the newest image added to
> a webcam directory, on my new server it is displaying the biggest
> file? Anyone know why?
> 
> <head><meta http-equiv="refresh" content="5"></head> <pre>
> <?php
> $latest_num = 0;
> 
> if ($handle = opendir('.')) {
>       while (false !== ($file = readdir($handle))) {
>        if (preg_match("/^test(\d+)/", $file, $matches)) {
>            if ($matches[1] > $latest_num) {
>                $biggest     = $matches[1];
>                $latest_file = $file;
>            }
>            // echo " $file\n";
>        }
>    }
> 
>    closedir($handle);
> }
> 
> echo "Latest file: $latest_file\n";
> 
> echo "<img src='$latest_file'>";
> 
> ?>
> </pre>
> 

The readdir function returns the files in the order stored on the
filesystem, in the same order as would be seen using 'ls -Ul' or 'ls -l
--sort=none'.  The reason for this is that it is faster not to sort the
files esp. for large directories. To be sure of getting the correct file
you'll need to do your own sorting.

-- 
Mike
Web Site: http://www.ice2o.com
JabberID: mpeters at jabber.org
Registered Linux User #247123

George Orwell was an optimist.



More information about the Wolves mailing list