Results 1 to 2 of 2

Thread: php list images in directory

  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).
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

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

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

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