Honestly, I've got not a sinle idea.
<?php
$somePath = 'randomfoldername';
$dir = new DirectoryIterator($somePath);
foreach ($dir as $fileinfo) {
if ($fileinfo->isDir() && !$fileinfo->isDot()) {
echo '<option value="$fileinfo->getFilename[]">'.$fileinfo->getFilename().'</option>';
}
}
?>
Tried to echo it and got that
$fileinfo->getFilename
in result.
Probably doing something terribly wrong. Not even sure if you know what I mean. I just want to use the value after it is being posted but can't make it work.
<?php
$somePath = 'randomfoldername';
$dir = new DirectoryIterator($somePath);
foreach ($dir as $fileinfo) {
if ($fileinfo->isDir() && !$fileinfo->isDot()) {
echo '<option value="'.$fileinfo->getFilename().'">'.$fileinfo->getFilename().'</option>';
}
}
?>
You need to write the value you want as the value property of the <option>
tag.
Try this:
<?php
$somePath = 'randomfoldername';
$dir = new DirectoryIterator($somePath);
foreach ($dir as $fileinfo) {
if ($fileinfo->isDir() && !$fileinfo->isDot()) {
$fileName = $fileinfo->getFilename();
echo '<option value="'.$fileName.'">'.$fileName.'</option>';
}
}
?>
Another thing is that you should probably avoid inline code. If you intend on using pure PHP you should reduce the <option>
...</option>
output into a variable and insert this variable alone into your HTML.
<?php
$somePath = 'randomfoldername';
$dir = new DirectoryIterator($somePath);
$options = '';
foreach ($dir as $fileinfo) {
if ($fileinfo->isDir() && !$fileinfo->isDot()) {
$fileName = $fileinfo->getFilename();
$options .= '<option value="'.$fileName.'">'.$fileName.'</option>';
}
}
?>
...
<select><?php echo $options ?></select>