Results 1 to 2 of 2

Thread: php list images in directory

Hybrid View

  1. #1
    Join Date
    Dec 2012

    php list images in directory


    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?

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

  2. #2
    Join Date
    Aug 2004
    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

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

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