Reputation: 267
I have a folder on the server with several different file types, and the only ones I want to appear in the <select>
list as options are the .json
files. Currently all the files are displaying as <options>
. I've only seen solutions for <input>
elements, but not for a <select>
. How can I display only the .json
files in the folder? Here is my element:
<form action="/server/php/data/process.php" method="post">
<select type="text" name="selectTemplate" onchange="loadTemplate()">
<option value="" selected="selected">Select Template</option>
<?php
foreach(glob(dirname(__FILE__) . '/server/php/data/*') as $filename){
$filename = basename($filename);
echo "<option value='" . $filename . "'>".$filename."</option>";
}
?>
</select>
</form>
Upvotes: 0
Views: 168
Reputation: 6159
Change this line:
foreach(glob(dirname(__FILE__) . '/server/php/data/*') as $filename){
like this:
foreach(glob(dirname(__FILE__) . '/server/php/data/*.json') as $filename){
Upvotes: 1