Solved

readdir() question

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 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

22 Experts available now in Live!

Get 1:1 Help Now