Images in folders

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all I'm a newbie and I need a good starting off point. Basically is there
a way in php where you can call up all images (jpgs and gifs) within a
directory. Also is there a way to format the images to come up in rows. Hope
this makes sense. Thanks in advance for the help.

Mikey p...

Re: Images in folders

You need a HTML tutorial... you don't need PHP to do any of that..

Quoted text here. Click to load it

Re: Images in folders

That was so funny i forgot to laugh...  Actually i know html pretty
well if memory serves you can't tell it to call up certain information
without using some sort of dynamic code. I was trying to be pretty
simple in my explination because i didn't want someone to hold my
hand, I just needed a starting off point. Basically i have the city
and state information carried over through a link. using
..php?city=nashville&state=TN. I wanted to use this information to make
a call to a certain folder where images reside for nashville TN. they
have a distinct path like ads/nashville/tn. And i wanted to pull all
the images from that folder and put them in rows. I hope this
explination helps avoid any smart @$$ comments.. :)

Quoted text here. Click to load it

Re: Images in folders

On 30 Aug 2004 06:25:48 -0700, (Mikey P) wrote:

Quoted text here. Click to load it

Use opendir() and readdir() to read the contents of the directory. You
can then echo the contents 1 by 1 and format as desired =)


digiServ Network
London, UK /

Re: Images in folders

Sorry Mike, I just assumed that you wanted to display some images that were
in folders... not that you wanted to dynamically display whatever is in a
given directory...

Quoted text here. Click to load it

Re: Images in folders wrote:
Quoted text here. Click to load it

  function fileListToStrings( $aPath )
    $i = 0;
    $files = array();
    if( $handle = opendir( $aPath ) )
      while( false !== ( $file = readdir( $handle ) ) )
        if( $file != "." && $file != ".." )
          $files[ ++$i ] = $file;
    return $files;

That will take a folder ( $aPath ) and return an array of filenames.  You
might want to modify it to only put image files into the array, I was using
it to get a complete listing.

Say your images folder is "/images", use it like this:

  $aFiles = fileListToStrings( "/images" );

  foreach( $aFiles as $aFile )
    echo "<img src=\"/images/$aFile\" alt=\"some alt text\">';

Re: Images in folders

Nik Coughin wrote:
Quoted text here. Click to load it

In case your newsreader mangles that code:

Site Timeline