How to delete a file from the server
<p>I have a javascript function below where it removes an appended file name from .listImage when the user clicks on the "Delete" button:</p>

<pre><code>function stopImageUpload(success, imagefilename){

      var result = '';

      if (success == 1){
         result = '&lt;span class="msg"&gt;The file was uploaded successfully!&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;';      
         $('.listImage').eq(window.lastUploadImageIndex).append('&lt;div&gt;' + htmlEncode(imagefilename) + '&lt;button type="button" class="deletefileimage"&gt;Delete&lt;/button&gt;&lt;br/&gt;&lt;hr/&gt;&lt;/div&gt;'); 
      }
      else {
         result = '&lt;span class="emsg"&gt;There was an error during file upload!&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;';
      }


      $(".deletefileimage").on("click", function(event) {

        $(this).parent().remove();

    });

      return true;   
}
</code></pre>

<p>But what I want to know is that when the user clicks on the delete button, I also want the file to be deleted from the server. How can this be done?</p>

<p>The folder the files are stored in is known as ImageFiles and the file name code on server side is <code>$_FILES["fileImage"]["name"]</code>.</p>

<p>The uploading of files into the server is on a seperate page on a php script which is below:</p>

<pre><code>&lt;?php
$result = 0;

if( file_exists("ImageFiles/".$_FILES['fileImage']['name'])) {
    $parts = explode(".",$_FILES['fileImage']['name']);
    $ext = array_pop($parts);
    $base = implode(".",$parts);
    $n = 2;

    while( file_exists("ImageFiles/".$base."_".$n.".".$ext)) $n++;
    $_FILES['fileImage']['name'] = $base."_".$n.".".$ext;

    move_uploaded_file($_FILES["fileImage"]["tmp_name"],
    "ImageFiles/" . $_FILES["fileImage"]["name"]);
    $result = 1;

}
    else
      {
      move_uploaded_file($_FILES["fileImage"]["tmp_name"],
      "ImageFiles/" . $_FILES["fileImage"]["name"]);
      $result = 1;


      }


?&gt;
</code></pre>
