I have a php function that is returning a list of files from a folder (image files), I would like to know if it possible for me to get a "blank" entry added into the dropdown list (so I can "not select" something in the list), as well as the files it finds in the folder, here is the function.
<?php
$folder = '../Pic/Upload';
echo '<select name="sabpic">'."
".
dropdown(image_filenames($folder), @$_POST['image']).
'</select>'."
".'</br></br>';
function image_filenames($dir)
{
$handle = @opendir($dir)
or die("I cannot open the directory '<b>$dir</b>' for reading.");
$images = array();
while (false !== ($file = readdir($handle)))
{
if (eregi('\.(jpg|gif|png)$', $file))
{
$images[] = $file;
}
}
closedir($handle);
return $images;
}
function dropdown($options_array, $selected = null)
{
global $sabpicname;
$return = null;
foreach($options_array as $option)
{
$return .= '<option value="'.$option.'"'.
(($option == $sabpicname) ? ' selected="selected"' : null ).
'>'.$option.'</option>'."
";
}
return $return;
}
?>
So currently I would get a dropdown with
- Pic1.jpg
- Pic2.jpg
I would like to have
- "blank line"
- Pic1.jpg
- Pic2.jpg
Thanks for the help.