title: Delete files with AJAX/PHP
body: <p><strong>The problem</strong></p>
  
  <hr>
  
  <p>I want to delete a file with <code>AJAX/PHP</code>.</p>
  
  <p>But the php says that the file name what I send with AJAX is not a file, but when I go directly to the link I can delete the files. Check out my current PHP, I've put in the IF/ELSE statement to check if the string is a file with: <code>is_file</code>, the result is <code>false</code>.</p>
  
  <p>Without <code>is_file</code> says this:</p>
  
  <p><code>Warning: unlink("image.jpg") [function.unlink]: Invalid argument in C:\wamp\www\images\users\delete.php on line 8</code></p>
  
  <p>The file what calls the ajax is inside the folder where are the files too what I want to delete.</p>
  
  <p><strong>The PHP</strong></p>
  
  <hr>
  
  <pre><code>&lt;?php
      // I save the file sources from the URL what was sent by AJAX to these variables.
      $photo_id = $_GET['photo_id'];
      $thumbnail_id = $_GET['thumbnail_id'];
  
      function deletePhotos($id){
          // If is a file then delete the file.
          if(is_file($id)){
              return unlink($id);
          // Else show error.
          } else {
              echo $id . " is not a file, or there is a problem with it.&lt;br /&gt;" ; 
          }
      }
  
      if(isset($photo_id)){
          deletePhotos($photo_id);
      }
      if(isset($thumbnail_id)){
          deletePhotos($thumbnail_id);
      }
  
   ?&gt;
  </code></pre>
  
  <p><strong>The AJAX</strong></p>
  
  <hr>
  
  <pre><code>function deletePhoto(photo, thumbnail){
  
          var photos = encodeURIComponent(photo);
          var thumbnails = encodeURIComponent(thumbnail);
  
          if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
          } else {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
  
          xmlhttp.onreadystatechange=function() {
              if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) {
                  document.getElementById("media").innerHTML=xmlhttp.responseText;
              }
          }
          xmlhttp.open("GET", "http://192.168.2.104/images/users/delete.php?photo_id=\""+photos+"\"&amp;thumbnail_id=\""+thumbnails+"\"", true);
          xmlhttp.send();
      }
  </code></pre>