title: PHP Delete File from Dropdown
body: <p>I have a dropdown list populated with files pulled from a directory using the PHP listed below and am trying to figure out how I can delete them using a delete button in the form when they're selected.</p>
  
  <pre><code>&lt;input type="hidden" name="Action" value="EDIT" /&gt;&lt;input type="hidden" name="Selection"  id="Selection" value="-1"&gt;&lt;div&gt;Below is the list of your saved codes. To edit your codes, select it from the list.&lt;/div&gt;
  &lt;select size="1" name="CodeList" id="CodeList"&gt;
  &lt;?php
     $directory = $directory = 'users/' . $_SESSION['username'];
     $filesContents = Array();
     $files = scandir( $directory ) ;
  
     foreach( $files as $file )
    {
     if ( ! is_dir( $file ) )
    {
     $filesContents[$file] = file_get_contents($directory , $file);
    echo "&lt;option&gt;" . $file . "&lt;/option&gt;";
    }
     }
     ?&gt;
     &lt;/select&gt;
  </code></pre>
  
  <p>Updating code as I go.</p>
  
  <pre><code>&lt;?php
     session_start();
      $directory = $directory = $_SERVER['DOCUMENT_ROOT'] . '/users/' . $_SESSION['username'];
      $file_to_delete = $_POST['CodeList'];
      if ( unlink ($directory.'/'.$file_to_delete) ) {
        echo $file_to_delete . " deleted.";
     } else {
  echo "Error.";
  }
  ?&gt;
  </code></pre>
  
  <p><strong><em>edited and updated code</em></strong></p>
  
  <p>Now says Warning: unlink(/myhome/root/public_html/users/Addiction/) [function.unlink]: No such file or directory in /home/revo/public_html/evo/avdeleteprocess.php on line 5
  Error.</p>
  
  <p>So its found the right folder, just not finding the file from the dropdown list selection.</p>
  
  <p><strong>Also edited to add</strong> I ran a var_dump($_POST) right after my delete script to see what it was pulling as the value of POST and it came back with: Error.array(1) { ["Action"]=> string(6) "Delete" }</p>