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

Before the while use:

echo '<select>';

In the while use:

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

After the while use:

echo '</select>';
commented: Very Helpful +0

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);  
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.