dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: php list images in directory

  1. #1
    Join Date
    Dec 2012
    Posts
    1

    php list images in directory

    Hello.

    I am new in programming.
    I would appreciate some help.

    I have a folder in my site where I save all images from snagit.
    But instead of seeing file names, I would like to see the images themselves with the last ones uploaded on top.

    Could you modify the file?
    Thanks.


    HTML Code:
     <body>
    
    <?php
        if ($handle = opendir('.')) {
        while (false !== ($file = readdir($handle)))
        {
            if ($file != "." && $file != "..")
            {
                $thelist .= '<LI>
    			
    			<a href="'.$file.'">'.$file.'</a>';
            }
        }
        closedir($handle);
        }
    ?>
    
    <P>List of files:</p>
    <UL>
    <P><?=$thelist?></p>
    </UL>
    
    
      
      
      
      
    
    </body>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    I would use glob() to get an array of all the image files, then use usort() in combination with file_mtime() to sort them by date, then finally do a foreach() loop on the sorted array for the HTML output, creating <img> tags instead of <a> tags (or wrapped by the <a> tags if you want the images to be links, too).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles