?
Solved

PHP Dir List To Dropdown

Posted on 2008-10-26
2
Medium Priority
?
284 Views
Last Modified: 2013-12-13
Hello Experts,

I have a PHP Script to read a Directorys contents which then makes a Drop Down selection of the files, the only problem with the script is it displays the . and .. directory structure links in the drop down which i dont want, i just want the files from the directory displayed, I have no idea how to get these out of the drop down...

Script is below.

Thanks,
Steve
<?php 
if ($handle = opendir('../files')) { 
    echo "<label><select name=\"URL\" id=\"URL\" >"; 
    while (false !== ($file = readdir ($handle))) { 
        echo "<option value=\"$file\">$file</option>"; 
    } 
    echo "</select></label>"; 
    closedir($handle); 
} 
?>

Open in new window

0
Comment
Question by:robsons995
[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 Comments
 
LVL 8

Accepted Solution

by:
fcardinaux earned 2000 total points
ID: 22806865

<?php 
if ($handle = opendir('../files')) { 
    echo "<label><select name=\"URL\" id=\"URL\" >"; 
    while (false !== ($file = readdir ($handle))) { 
        if ('.' === $file ¦¦ '..' === $file) continue;
        echo "<option value=\"$file\">$file</option>"; 
    } 
    echo "</select></label>"; 
    closedir($handle); 
} 
?>

Open in new window

0
 

Author Comment

by:robsons995
ID: 22806891
I was getting an error with the above script "Parse error: syntax error, unexpected T_STRING in..."

Changed to the one below and it works fine now, thanks for your quick and accurate help!!! :-)

Steve.
if ($handle = opendir('../files)) { 
    echo "<label><select name=\"URL\" id=\"URL\" >"; 
    while (false !== ($file = readdir ($handle))) { 
        if ('.' === $file) continue;
        if ('..' === $file) continue;
        echo "<option value=\"$file\">$file</option>"; 
    } 
    echo "</select></label>"; 
    closedir($handle); 
} 
?>

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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 i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …
Suggested Courses

770 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