0

I have a drop down list which is populated from a directory on my server, I want to be able to select an item from the list and it will either download or open the file.

This is my code so dfar:

List.php

<div align="center">
<form name="marketingpages">
<select name="menu" onChange="top.location.href=this.options[this.selectedIndex].value;" value="GO" id="marketinglist">
      <option value="" selected="selected">-----</option>
  <?php 
       foreach(glob(dirname(__FILE__) . '/policies/*') as $filename){
       $filename = basename($filename);
       echo "<option value='" . $filename . "'>".$filename."</option>";
    }
?>

</select>
</form>
</div>

When I select an item from the list though I'm just directed to a page where I get the message "Object Not Found" and the URL doesn't contain the sub directory 'policies' which is referenced in the code.

Can anyone help?

dev_py_uk
  • 418
  • 1
  • 5
  • 20

1 Answers1

4

You didn't add policies in the option.value. Try this:

echo "<option value='policies/" . $filename . "'>".$filename."</option>";
JNF
  • 3,696
  • 3
  • 31
  • 64
  • I've also tried adding target="_blank" so that these files will open in a separated window but cant get it in php code and dont know where to add this to the html – dev_py_uk Nov 09 '15 at 14:38
  • @oggle0901 have a look at this Q http://stackoverflow.com/questions/1574008/how-to-simulate-target-blank-in-javascript – JNF Nov 09 '15 at 14:47