title: downloading files from a dropdown menu
body: <p>I am trying to add a drop-down menu displaying files located in directory (uploads) and have users selecting (a) file(s) to download to their local machine. 
  I have use the following PHP code to populate an array and a pseudo HTML code to generate the drop-down menu, which is supposedly passing the name of the selected file to a JavaScript which is to force the browsers to download the file. 
  There two issues here, 1- it seems the name of the selected file (line 15) is not passed to the JavaScript (line 23); 2- Even if I do force the file name (line 27), I receive a permission error preventing the file from being downloaded.
  Since I am totally inexperienced in coding, any help I can get, is highly appreciated.  </p>
  
  <p>PHP: 
      
  
  <pre><code>$dirname = realpath(__DIR__ . '/..' . '/uploads');
  
  $files = array();  
  $dir = opendir($dirname);  
  while(($file = readdir($dir)) !== false)
  {  
  if($file !== '.' &amp;&amp; $file !== '..' &amp;&amp; !is_dir($file)) 
   {     
   $files[] = $file;       
   }     
  }  
  closedir($dir);    
  sort($files);  
  $files[] = 'Select a document to download';  
  echo '&lt;select name="download" class="pickupzone" onchange="myDownload(this.value)"&gt;';   
  for($i=0; $i&lt;count($files); $i++)   
  {    
    echo '&lt;option value="" selected="selected"&gt;' . $files[$i] . '&lt;/option&gt;';    
  }  
  echo '&lt;/select&gt;';  
  ?&gt;
  </code></pre>
  
  <p>JavaScript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  function myDownload(val)  
  {  
   if (val == 'Select a document to download') return;   
    var link = document.createElement("a");  
    link.download = val;  
    link.href = '../uploads/';  
    link.click();  
    window.alert('downloading: ' + link + link.download);
  
  &lt;/script&gt;
  </code></pre>