Jump to content

Recommended Posts

Hi, i have a code that reads a directory and puts all the images within the directory into table format with links underneath. In my directories I have images that are named

 

1.jpg

2.jpg

3.jpg etc

 

and i have images that are named

 

1b.jpg

2b.jpg

3b.jpg

 

how can i change this code so that all the images with b.jpg is not included when the code is run to view images within a directory?

 

<?php
$r = 0;
for($n=0; $n<$total_items; $n++) {
if($n !=0 && fmod($n, 5) == 0) {
echo "</tr><tr>";
}
      $imageL= $path.$item[$n];
      $img_path="http://ve-creative.com/test/8/$imageL";
            // display the item
		echo '<td><center><p><a href="'.$img_path .'"><img src= "'.$path.$item[$n] .'" height="100" width="100"></a></p></center>';
            echo "<center><p><a href=imgEdit.php?img=$img_path> > Edit Image < </a></p></center><br></td>";  

}

if($r>0) {
for($m=$r; $m<5; $m++) {
echo "<td> </td>";
}
}

?>

Link to comment
https://forums.phpfreaks.com/topic/148915-solved-exclude-certain-files/
Share on other sites

Hi

 

Just check the end of the string containing the file name.

 

<?php
$r = 0;
for($n=0; $n<$total_items; $n++) {
if($n !=0 && fmod($n, 5) == 0) {
echo "</tr><tr>";
}
      $imageL= $path.$item[$n];
  if (substr($imageL,-5) != 'b.jpg')
  {
      $img_path="http://ve-creative.com/test/8/$imageL";
            // display the item
         echo '<td><center><p><a href="'.$img_path .'"><img src= "'.$path.$item[$n] .'" height="100" width="100"></a></p></center>';
            echo "<center><p><a href=imgEdit.php?img=$img_path> > Edit Image < </a></p></center><br></td>";  
	}
}

if($r>0) {
for($m=$r; $m<5; $m++) {
echo "<td> </td>";
}
}

?>

 

If there were several different varieties you wanted to avoid displaying then a regular expression check might be better.

 

All the best

 

Keith

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.