php - Add blank line to the dropdown? -
i have php function returning list of files folder (image files), know if possible me "blank" entry added dropdown list (so can "not select" in list), files finds in folder, here function.
<?php $folder = '../pic/upload'; echo '<select name="sabpic">'."\n". dropdown(image_filenames($folder), @$_post['image']). '</select>'."\n".'</br></br>'; function image_filenames($dir) { $handle = @opendir($dir) or die("i cannot open directory '<b>$dir</b>' 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 $option) { $return .= '<option value="'.$option.'"'. (($option == $sabpicname) ? ' selected="selected"' : null ). '>'.$option.'</option>'."\n"; } return $return; } ?>
so dropdown with
- pic1.jpg
- pic2.jpg
i have
- "blank line"
- pic1.jpg
- pic2.jpg
thanks help.
according code replace $return = null;
$return = "<option></option>";
function dropdown($options_array, $selected = null) { global $sabpicname; $return = "<option></option>"; foreach($options_array $option) { $return .= '<option value="'.$option.'"'. (($option == $sabpicname) ? ' selected="selected"' : null ). '>'.$option.'</option>'."\n"; } return $return; }
Comments
Post a Comment