Solved

readdir() question

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

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