Jump to content

listing images


fricx

Recommended Posts

Hello, I am trying to list images from folder, and i have managed to that. But, I want to limit number of images the code will show. Here is my code:

 

<?php

$imgdir = 'uploads/image/'; 
$allowed_types = array('jpg','jpeg'); 
$a_img = glob($imgdir."*.{".implode(',',$allowed_types)."}",GLOB_BRACE);
sort($a_img);

echo '<table cellspacing="0" cellpadding="6"><tr>';         
foreach ($a_img as $img) {
  if ($colCount % 6.5 == 0) echo "</tr><tr>";
  $colCount++;
  $showimage = basename($img);
  echo '<td><div class="smallpic" style="width:100px;height:75px;"><a href="../index.php?pic='.$showimage.'"><img src="../uploads/image/'.$showimage.'" width="100" height="75" border="0" onclick="changeImg(velika, "'.$showimage.'")" /></a></div</td>';
}
echo "</tr></table>";

?>

 

So my question is how to limit above code to show only for example 4 images.

 

Link to comment
https://forums.phpfreaks.com/topic/188030-listing-images/
Share on other sites

You're welcome. I do tend to find that folks 'forget' about the range of array (and same for string) functions and just need reminding. If you don't mind, I've marked this thread as "solved" (though that's normally your responsibility) -- if you think it's not, please do click the button to mark it not solved.

Link to comment
https://forums.phpfreaks.com/topic/188030-listing-images/#findComment-993414
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.