Reputation: 411
Is it possible (I am assuming not) to populate a drop down list from files that are on my website, say in the images folder? in a html form?
<select name="s1">
<option value="" selected="selected">-----</option>
<?php
foreach(glob('/images/*') as $filename){
$rest = substr($filename, 7);
echo "<li><a href='#'>".$rest."</a></li>";
}
?>
</select>
Upvotes: 1
Views: 11165
Reputation: 15053
Try it like this:
<select name="s1">
<option value="" selected="selected">-----</option>
<?php
foreach(glob(dirname(__FILE__) . '/images/*') as $filename){
$filename = basename($filename);
echo "<option value='" . $filename . "'>".$filename."</option>";
}
?>
</select>
Upvotes: 4
Reputation: 21845
You can use scandir
- http://php.net/manual/en/function.scandir.php
Then just run a foreach
on the returned array and echo <option>
for each one.
Upvotes: 5