سؤال

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
}
?>
هل كانت مفيدة؟

المحلول

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 } ?>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top