I am trying to populate an HTML form's drop down list with the contents of the current directory. I attempted to use PHP's scandir() function to output these files as an array and then feed them into the option's value tag within the HTML form.
I looked at various solutions available on SO and outside, but none seemed to work for me.
This is how my code looks like right now:
<form action="" >
<input type="submit" class="Links" value="Select Input">
<select >
<?php
$dir="./inputfiles/";
$filenames = scandir($dir);
foreach($filenames as $file){
echo '<option value="' . $filenames . '">' . $filenames . '</option>';
}
?>
</select>
</form>
For now I'm getting absolutely no options in the drop down menu.
I am very new to PHP and would appreciate your feedback as to how to make this work.
Further Changes:
I tried the solutions given below, and none seemed to work. I changed the code to check whether the PHP script is able to output any variable or not in the html forms list.
<form action="" >
<input type="submit" class="Links" value="Select Input">
<select >
<?php
$someval = "Video";
echo '<option value="value"> ' . $someval .' </option>';
?>
</select>
</form>
It displays ' . $someval .' instead of Video in the menu bar
$dir="../inputfiles/";inputfiles/