Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member
    Join Date
    Feb 2005
    Location
    Canada
    Posts
    435
    Member #
    8983
    I am looking for a way to list all images in a directory using php and excluding all other files, is there any way to do this (img types would all be jpg, and I want them listed with a discription although i figure using the file name as the description would work
    Thee Pyro Wolf

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    PHP Code:
    <?php

    // where the images are stored
    $directory "./images";

    // open the directory
    $dir opendir$directory );

    // loop through it, looking for any/all JPG files:
    while (false !== ($fname readdir$dir ))) {

    // parse path for the extension
    $info pathinfo($directory $fname);

    // display only if .jpg
    if ( strtolower($info['extension']) == 'jpg' )
    {
    // here's where you would examine the filename and
    // split it to get the description (which is part
    // of the filename)?  You'll have to figure out how
    // you want to do that.

    echo "<img src='$directory/$fname' alt='' /><br />\n";
    echo 
    "$fname <br />";
    }

    }
    ?>


  4. #3
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Better yet, in this context, would be to use the [phpfunction]glob[/phpfunction] function. you'll want to prefix the glob with the directory, so your glob would likely be something like [minicode]images/*.jpg[/minicode].


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:11 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com