1

I'm trying to get my select dropdown box to populate with the name of the images in my directory. Currently, using the following, it is populating the correct number of items, but not displaying the name. Php is not my forte, so any tips would be greatly appreciated.

<?php 
$dir = '/public_html/bioImages'
$directory = scandir($dir);
for each $directory as $filename){ 
?>
<option value="<?php echo $filename;?>"> <?php echo $filename;?> </option>
<?php
}
?>
user3476623
  • 13
  • 1
  • 6

1 Answers1

1

There are several issues with your code; Missing semicolons and brackets. After fixing those, it should work.

This is what your code should look like:

<?php 
    $dir = '/public_html/bioImages';
    $directory = scandir($dir);
    foreach ($directory as $filename){ 
?>
<option value="<?php echo $filename;?>"> <?php echo $filename;?> </option>
<?php } ?>
jadnco
  • 81
  • 4
  • Thanks for the missing stuff, as I said, I'm not really fluent with php (haven't really used it). However, it is still not showing the filename, only blank options. I'm not sure exactly what it going on. I'm using cpanel hosting, if that makes any difference? – user3476623 Mar 29 '14 at 22:27
  • 1
    @user3476623 Are you sure that you have the correct directory in `$dir`? Try removing the first slash. – jadnco Mar 29 '14 at 22:56
  • It has to be the correct directory-- it's the only place it could be. I even replaced the $dir with the full file path for the site instead of the directory from the hosting site and that made no difference. Here is the site: http://elizabethegreene.com/bioImages/ It is supposed to show up on http://elizabethegreene.com/form.html when two image questions are marked 'yes' and the drop down menu shows up, and it is not doing so. – user3476623 Mar 30 '14 at 00:37
  • @user3476623 `$dir` should be `bioImages` without the `public_html` or any slashes. – jadnco Mar 30 '14 at 00:50
  • Changed that, still nothing. I'm so confused. :/ – user3476623 Mar 30 '14 at 01:31
  • @user3476623 Sorry I could't help you. I have no idea what the issue is :( – jadnco Mar 30 '14 at 03:10
  • Your answer worked; I needed to change my file format to .php instead of .html. So simple, and yet it caused me all sorts of issues. Thanks for your help. – user3476623 Apr 01 '14 at 19:30