alexjewell
10-16-2007, 11:05 PM
Hey, I'm trying to pull 15 random images from a directory and display them. There are always 15 images that are attempted to display, but there is always at least 1 image displayed without a source, and therefore less than 15 actual images show up. You can see the massacre here: http://www.alexjewell2.com/clients/quinn/tickerIdea.php
Below is my code:
$dirpath = 'imgs/gallery/t/';
$dh = opendir($dirpath);
$i = 0;
while ($f = readdir($dh)) {
if ($f =='.'||$f=='..') { continue; }
if (!@getimagesize($dirpath.$f)) { continue; }
$imgs[$i]=$f;
$i++;
}
$st = (count($imgs)>=15)?15:count($imgs);
for ($n=$st;$n>0;$n--) {
$r = mt_rand(0,count($imgs));
echo '<a href="gal.php?file='.$imgs[$r].'"><img src="'.$dirpath.$imgs[$r].'" /></a>';
ksort($imgs);
unset($imgs[$r]);
}
Any ideas on what undefined offset means and why line 34, unset($imgs[$r]);, is causing so much trouble? And if line 34 isn't the issue, what is? Thanks.
Below is my code:
$dirpath = 'imgs/gallery/t/';
$dh = opendir($dirpath);
$i = 0;
while ($f = readdir($dh)) {
if ($f =='.'||$f=='..') { continue; }
if (!@getimagesize($dirpath.$f)) { continue; }
$imgs[$i]=$f;
$i++;
}
$st = (count($imgs)>=15)?15:count($imgs);
for ($n=$st;$n>0;$n--) {
$r = mt_rand(0,count($imgs));
echo '<a href="gal.php?file='.$imgs[$r].'"><img src="'.$dirpath.$imgs[$r].'" /></a>';
ksort($imgs);
unset($imgs[$r]);
}
Any ideas on what undefined offset means and why line 34, unset($imgs[$r]);, is causing so much trouble? And if line 34 isn't the issue, what is? Thanks.