readdir() question

Posted on 2011-09-23
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

$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\"/>

Open in new window

Question by:jaxbrian
  • 2

Accepted Solution

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\"/>

Open in new window


Author Comment

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.

Expert Comment

ID: 36591103

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

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


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php date - compare 4 40
PHP_POST() error message 9 44
php string masking 4 29
Facial recognition to look through the whole database for a person 3 43
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
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.

896 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now