limit php script (fetch all photos in a directory) to 7
<p>can someone please help, i am using a script in php to fetch all the photos in a directory, but i want it to limit it to only fetch 7 images in total, the ones it select can be random.</p>

<p>can anyone suggest a way i can do this thanks.</p>

<pre><code>&lt;?php if (isset($_SESSION['user_id'])) { 
        if ($user['id'] == $_SESSION['user_id']){
            if ($user['account_type'] == "Escort"){ ?&gt;
&lt;div class="profile_photos_drop"&gt;&lt;iframe src="includes/mod_photo_uploads/small_pics.php" width="184" height="194" scrolling="no" style="overflow:hidden; margin-top:-4px; margin-left:-4px; border:none;"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;? } } } ?&gt;
 &lt;?php
$profile_bits = get_profile_bits();
while ($profile = mysql_fetch_array($profile_bits)) { 
$dirname = "./data/photos/".$profile_id."/";
$images = scandir($dirname);
$ignore = Array("_cover.jpg", "_default.jpg", "_starlight.jpg", "_starlight_thumb.jpg", "thumb_pic1.jpg", "thumb_pic2.jpg", "thumb_pic3.jpg", "thumb_pic4.jpg", "thumb_pic5.jpg", "thumb_pic6.jpg", "thumb_pic7.jpg", "thumb_pic8.jpg", "thumb_pic9.jpg", "thumb_pic10.jpg", "thumb_pic11.jpg", "thumb_pic12.jpg", "thumb_pic13.jpg", "thumb_pic14.jpg", "thumb_pic15.jpg", "thumb_pic16.jpg");
foreach($images as $curimg){
if(!in_array($curimg, $ignore) &amp;&amp; preg_match("/\.jpg$/i", $curimg)) {
echo "&lt;a href=\"".$dirname.$curimg."\" rel=\"shadowbox\" title=\"&lt;strong&gt;{$profile['display_name']}'s Photo's&lt;/strong&gt;\"&gt;&lt;img src='".$dirname.$curimg."' class=\"profile_photos\" width=\"170\" height=\"150\" &gt;&lt;/a&gt;";
};
} 
}
?&gt;
</code></pre>
