Hi, I am trying to figure out how to use a method such as readdir to display a list of files in a specified directory and then when a file is selected in the list it is stored to a variable. Any help with this would be much appreciated.
what do you have so far, and what's the specific issue? or do you expect some one to write it for you?
This is what I have. Right now it doesn't display anything but white in the drop down. Path is correct and verified.
<select size="1" name="project"> <?php $files = array(); if ($handle = @opendir('/home/mysite/public_html/beta/upload/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $files[] = $file; } } closedir($handle); if(count($files) > 0) natcasesort($files); foreach($files as $output){ echo "$output\n"; echo '<option value="$output\n"</option>'; } } ?> </select>
remove the @, it just suppresses errors, and the errors are what you want to see, i suspect the directory is wrong.
using single qoute means variable's name will be included into the text and not it's value.
and a select options looks like this:
printf('<option value="%1$s">%1$s</option>' , $output );
Including the actual select element might be a good idea
echo '<select>'; foreach() { } echo '</select>';
Also, if you intend to send it to the server, you will need a form element and a submit. And the select element will need a name attribute.