0

Hey everyone,

Been working on a php snippet which finds the names of all the files in a Directory and populates them into a drop down box. Which would then allow me to select that file, click a submit button and delete them.

Here is what I have SO

<?php
$path = "uploads/";
$handle = opendir($path);   

while ($file = readdir($handle)) {
    if (substr($file,0,1) != ".") {
    echo "<option value ='$file'></option>";
    }   
}
closedir($handle);  
?>

This does not work, however, Replace the echo with:

echo $file . "<br>";

And it does work, Any help? Thanks guys

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by bradly.spicer
1

Before the while use:

echo '<select>';

In the while use:

echo "<option value ='$file'>$file</option>"; 

After the while use:

echo '</select>';
Votes + Comments
Very Helpful
1

Thanks! Very helpful :)

Can't believe it was that simple.

Just to clarify incase anybody finds this in a search engine, the result was:

<?php
$path = "uploads/";
$handle = opendir($path);   
echo '<select>';     
while ($file = readdir($handle)) {
    if (substr($file,0,1) != ".") {
    echo "<option value ='$file'>$file</option>";
    }   
}
echo '</select>';
closedir($handle);  
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.