title: Button to delete a file using php
body: <p>I have a php loop which displays all of the files in a directory:</p>
  
  <pre><code>&lt;?php
  
      // Define the full path to your folder from root
      $filepath =  'castlewp/cv/'; // The place the files will be uploaded to.
      $path = $_SERVER['DOCUMENT_ROOT'] . $filepath;
  
      // Open the folder
      $dir_handle = @opendir($path) or die("Unable to open $path");
  
      // Loop through the files
      while ($file = readdir($dir_handle)) {
  
      if($file == "." || $file == ".." || $file == "index.php" || $file == ".htaccess" || $file == ".htpasswd" )
  
          continue;
          echo "&lt;li&gt;&lt;a href=\"$file\"&gt;$file&lt;/a&gt;&lt;/li&gt;";
  
      }
      // Close
      closedir($dir_handle);
  ?&gt;
  </code></pre>
  
  <p>I am trying to find a way of adding a button next to each file which will delete the file. I have been playing around with php unlink but so far I have only been able to delete all of the files whenever a person accesses the script, this isn't what I want.</p>
  
  <p>As far as I can tell this is a fairly simple thing to add but my knowledge of PHP is minor so any suggestions would be appreciated.</p>