Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts

    Getting all the images from a folder and displaying them

    My picture upload system works by giving each member their own folder created when they registered. When they upload pictures, it puts them in that folder, now I want to create a script that will display all the pictures on a page, resized to 100x100 with 3 columns and unlimited rows. Any ideas on this?

  • #2
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    check out the dir functions on php.net then do a while loop and put all the image names into <img> tags. Like This:

    PHP Code:
      <?php
    if ($handle opendir('../thumbs/')) {
        while (
    false !== ($file readdir($handle))) {
            if (
    $file != "." && $file != ".." && $file != ".DS_Store" && substr($file01) !== '.') {
                echo 
    '<img style="border: 1px solid #666666;" src="../thumbs/'.$file.'" width="200" height="110" /><br><br><b>thumbs/'.$file.'</b><br><br><br>';
            }
        }
        
    closedir($handle);
    }
    ?>
    Wrote that just for you !

    It also removes . and .. and .DS_Store

  • Users who have thanked the-dream for this post:

    Ludatha (01-26-2008)

  • #3
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    Hey, thanks allot, after a bit of fiddling I got it to work

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    PHP Code:
    $folder '/images/user'// specify images folder
    $images glob$folder '/*.*' ); // grab images
    $images array_chunk$images); // split it into rows of 3

    echo '<table>'// start table
    foreach ( $images as $row // iterate rows
    {
        echo 
    '<tr>';
        foreach ( 
    $row as $img // iterate columns
        
    {
            echo 
    '<td><img src="'$img'" width="100" height="100" /></td>'// display image
        
    }
        echo 
    '</tr>';
    }
    echo 
    '</table>'// end table 

  • #5
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    You're welcome.

    Have fun !


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •