Solved

readdir() question

Posted on 2011-09-23
3
307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

738 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