Jump to content

[SOLVED] exclude certain files


anf.etienne

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

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.