-
[PHP] Dir Help
Hey,
I have just designed this script, there is a folder with 10 images in it...
01.jpg
01t.jpg
02.jpg
02t.jpg ect... all the way to 05.jpg
I want it to display 4 images per div, so it should echo 4 images in 1 div then 1 image in another div because I DONT want the script to display the images with t in it so it will NOT display 01t.jpg ect...
Can you help me fix my code so it doesnt take into account the images with a t in the name.
PHP Code:
<?php
$image_dir = "";
/* settings */
$per_column = 4;
/* step one: read directory, make array of files */
if ($handle = opendir($image_dir)) {
while (false !== ($file = readdir($handle)))
{
if ($file != '.' && $file != '..')
{
$files[] = $file;
}
}
closedir($handle);
}
/* step two: loop through, format gallery */
if(count($files)){
echo "<div>";
foreach($files as $file){
$count++;
echo '
<span><img width="44" height="44" src="'$image_dir''$file'" alt="#" /></span>
';
if($count % $per_column == 0) { echo '</div>'; }
}}
else
{
echo ''; // Error no images
}
echo "";
}
?>
Dan =)
-
Sorry, I mean I want the script to only show images with a t and not show images without a t in it =)
-
Tbh theres probs an easier way than what I'm gonna say but you could use str_replace and create a new var and replace t with x or something and then check if the original file is equal with the new str replaced file
-
Ok....
You have lost me!
What I was thinking is a little bit of script that will say if the file has a t in it continue if not skip?
Dan
-