Solved

readdir() question

Posted on 2011-09-23
3
299 Views
Last Modified: 2012-05-12
I am trying to use the readdir() function to read all the content of a folder so I can display the images like in the code below. when i use this function it always gives me a " . " and a " .. "   How do I not include them in the results?
thanks for any help with this


B
$dir = opendir("photos/food");
while (($file = readdir($dir)) !== false)
  {
echo   "<a href=\"photos/food/" . $file . "\"" . "rel=\"lightbox[vacation1]\" title=\"\">
            <img src=\"photos/food/" . $file . "\"" . "alt=\"\" height=\"50px\" width=\"50px\"/>
          </a>";
  }

Open in new window

0
Comment
Question by:jaxbrian
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
nrbreen earned 500 total points
ID: 36590545


dot and dotdot are always returned  representing the current folder and parent folder respectively.

$dir = opendir("photos/food");
while (($file = readdir($dir)) !== false)
  if ($file<>'.' && $file<>'..')
    {
      echo   "<a href=\"photos/food/" . $file . "\"" . "rel=\"lightbox[vacation1]\" title=\"\">
            <img src=\"photos/food/" . $file . "\"" . "alt=\"\" height=\"50px\" width=\"50px\"/>
          </a>";
    }

Open in new window

0
 
LVL 2

Author Comment

by:jaxbrian
ID: 36590575
thank you very much, do you think you could explain a little bit about <>? if not maybe a link to where I can read about it.
0
 
LVL 3

Expert Comment

by:nrbreen
ID: 36591103

if ($file<>'.' && $file<>'..')

is
  if  ( $file    is not equal to   '.'    and     $file     is not equal to     '..'  )

     
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Checkout Page Input Field not aligned 1 26
What does this formatting equate to? 7 18
Output in PHP throwing alignment of data off issue 12 42
Wordpress Pagination 1 28
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question