Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.