[Wolves] Problem with code

Mike Peters mike at ice2o.com
Wed Feb 16 21:31:38 GMT 2005


On Wed, 16 Feb 2005 20:00:35 +0000
Wayne Morris <wayne at machx.co.uk> wrote:

> 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 inlarge directories. To be sure of getting the correct file
you need to do your own sorting.

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

Mark's Dental-Chair Discovery:
	Dentists are incapable of asking questions that require a
simple yes or no answer.



More information about the Wolves mailing list