PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
nicademus
Forum Newbie
Posts: 14 Joined: Tue Apr 14, 2009 8:36 am
Post
by nicademus » Tue Apr 28, 2009 8:08 am
Hello All!
I am close to getting this script to work but have hit a roadblock. I am trying to get the images from a folder to be stored in separate variables - something like a mysql_fetch_array for images in a folder.
This is what I have now:
Code: Select all
<?php
$path = "img/images/co_images/playfulpromises/small/";
$dirname = "img/images/co_images/playfulpromises/small/";
$images = scandir($dirname);
foreach($images as $file)
{
if ($file != "." && $file != "..")
{
$files[] = $file;
}
$size_array = count($file);
$i=0;
while($i<$size_array)
{
?>
<img src="<?php echo $path ?><?php echo $file ?>" /><br /><br />
<?php
$i++;
}
}
?>
It displays all of the images but I cannot figure out how to get each image into a separate variable to be called into an <li> as an img src.
Thanx a million!
Last edited by
Benjamin on Tue Apr 28, 2009 1:28 pm, edited 1 time in total.
Reason: Changed code type from text to php.
ben.artiss
Forum Contributor
Posts: 116 Joined: Fri Jan 23, 2009 3:04 pm
Post
by ben.artiss » Tue Apr 28, 2009 9:52 am
Is this the kind of thing you had in mind?
Code: Select all
<?php
$path = "img/images/co_images/playfulpromises/small/";
$images = scandir($path);
$files = array();
foreach ($images as $file) {
if ($file != "." && $file != "..") {
$files[] = $file;
}
}
if (count($files)>0) {
echo '<ul>';
foreach ($files as $file) {
echo '<li><img src="'.$path.$file.'" alt="" /></li>'."\n";
}
echo '</ul>';
}
?>
Hope that points you in the right direction if you haven't fixed it already
Last edited by
Benjamin on Tue Apr 28, 2009 1:29 pm, edited 1 time in total.
Reason: Changed code type from text to php.