Is it possible:create/display an array from an image folder

Help Please–Is it possible to create and then display an array from an image folder. Using Dreamweaver, we have an image folder and would like to access the images. If we create a database, this can be done. Can you do it without creating a database? Is there a way to write a code that goes into the image folder and displays the images. Any direction would be appreciated.

With the help of this community, we have come a long way in a short time. Thanks for all your help! :o

opendir() should get your rolling.

We found a code that we incorporated into our page. It displays the images, not exactly as we will have it when we are done but we know what we are doing with the way it will look–at least for now we think we do. However the code below will also display the filenames along with the images. Within the following code–how do we have the filenames not show? Thanks for the help so far. We are just trying to display images from a folder and not a directory which is why we went with the glob. Seems to work better.

.img{
width:75px;
height:75px;
}

#main{
width: 30px;
position: absolute;
left: 15%;
top: 100px;
}
–>

<?php

/* alpharead version 3: This function returns an array
containing the names of the files inside any given
folder, excluding files that start with a ‘.’, as well
as the filenames listed in the ‘$killit’ array. This
array is sorted using the ‘natural alphabetical’
sorting manner. If no input is given to the function,
it lists items in the script’s interpreted folder.
Version 3 fixes a MAJOR bug in version 2 which
corrupted certain arrays with greater than 5 keys and
one of the supposedly removed filenames.
written by Admiral at NuclearPixel.com */

function alpharead3($dir){
if(!$dir){$dir = ‘.’;}
foreach(glob("$dir/*") as $item){$sort[]=
end(explode(’/’,$item));}

$killit = array(‘index.html’, ‘index.php’,
‘thumbs.db’, ‘styles.css’);
$killcounter = 0;
foreach($sort as $sorteditem){
foreach($killit as $killcheck){
if(strtolower($sorteditem) == strtolower($killcheck))
{unset($sort[$killcounter]);}
}$killcounter++;}
if($sort){natsort($sort);}
foreach($sort as $item){$return[]= $item;}

if(!$return){return array();}
return $return;
}

//some basic usage

$folder = ‘images’;
foreach(alpharead3($folder) as $item)
{
echo ‘’.$item.“n”;
}

?>

written by Admiral at NuclearPixel.com

There is your answer :wink: We don’t provide support on third-party scripts.

You could try this:

echo '<img src="'.$folder.'/'.$item.'"
class="img">n'; 

Zyppora – Thanks for the help. Couldn’t get it to work at first as I somehow inserted a single quote into the line when I was correcting it and I just couldn’t see it. Got rid of it and everything works great.

Having a problem with the debugging. Sometimes it displays and sometimes it doesn’t. Working with MAMP and Dreamweaver on a Mac. Will work on solving this as I understand how important this is.

Thanks again.

Sponsor our Newsletter | Privacy Policy | Terms of Service