Break WHILE with readdir
Posted: Mon Dec 05, 2011 2:24 am
I have an image directory for user images. And when they want to change pictures, it shows the 4 most recent ones. How do I limit this with my code:
Code: Select all
<?php
$imgDir = "./ppics/".$fname.$lname;
$handler = opendir($imgDir);
$ignore = array('.','..','Thumbs.db');
while($file = readdir($handler)) {
if(!in_array($file,$ignore)) {
echo '<a href="./assets/changePic.php?img='.$file.'" name="pic_'.$file.'"><img src="'.$imgDir.'/'.$file.'" alt="image_'.$file.'" style="width:50px;"></a> ';
}
}
?>