SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: php image array

  1. #1
    SitePoint Member
    Join Date
    May 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb php image array

    I'm trying to display all the images inside a certain directory. Here's what I have so far...

    Code:
     <?php
    
    $dir1 = "001/"; $images1 = scandir($dir1);
    
    $i1 = sizeof($images1); 
    
    foreach ($images1 as $value)
    
    { echo "<img src='001/" . $images1[$i1]; . "' alt='' />" }
    
    ?>

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,615
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    You were close. However, the foreach statement wasn't used correctly, the use of sizeof doesn't make any sense, and your echo statement was invalid HTML.

    PHP Code:
    $dir1 "001/"

    $images1 scandir($dir1);

    //if there are items in the directory
    if(!empty($images1)){

        
    //for each item found in the directory
        
    foreach ($images1 as $item){ 

            
    //if the item found is not a directory, is not a symbol for another directory (".." or ".")
            
    if(!is_dir($dir1.$item) && $item != ".." && $item != "."){
                
                
    //print the image HTML tag
                
    echo '<img src="' $dir1 $item '" alt="">'

            }

        }


    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Member
    Join Date
    May 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's working now, thank you so much!


Bookmarks

Posting Permissions

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