title: Upload image to server not working
body: <p>Before I start, I want to clarify that I did extensive research on this but none of the solutions work.</p>
  
  <p>I have been create a app that allow to users upload your images to create an event.</p>
  
  <p>I tried to upload this images to my server, and I received successfully in the response but when I check my directory whether the image is not there, I assume that did not uploaded.</p>
  
  <p>Before I upload the image I check whether the image already exists in folder, to do this I have to create a function using curl to verify that, because function <code>file_exists</code> did not working.</p>
  
  <p>I don't know what I have to do more, to get this.
  P.S: I'm using backbone.js to build my application.</p>
  
  <p>here my code:
  html:</p>
  
  <pre><code>&lt;form id="uploadimage" action="" method="post" enctype="multipart/form-data"&gt;
                  &lt;input type="file" name="file" id="file"&gt;
              &lt;/form&gt;
  </code></pre>
  
  <p>view.js</p>
  
  <pre><code>events: {
          'click #guardar' : 'guardarEvento',
          'click #guardarImagem' : 'guardarImagem',
          'change input[type=file]' : 'uploadFile'    
      },
  
  guardarImagem: function(){
  
      var fileInput = document.getElementById('uploadimage');
      console.log(new FormData(fileInput));
      $.ajax({
          url: "js/views/ajax_php_file.php", // Url to which the request is send
          type: "POST",             // Type of request to be send, called as method
          data: new FormData(fileInput), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
          contentType: false,       // The content type used when sending data to the server.
          cache: false,             // To unable request pages to be cached
          processData:false,        // To send DOMDocument or non processed data file it is set to false
          success: function(data){   // A function to be called if request succeeds
              console.log(data);
          }
      }); 
  },
  </code></pre>
  
  <p>ajax_php_file.php</p>
  
  <pre><code>&lt;?php
  if(isset($_FILES["file"]["type"])){
      $validextensions = array("jpeg", "jpg", "png");
      $temporary = explode(".", $_FILES["file"]["name"]);
      $file_extension = end($temporary);
  
      if ((($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg")
      ) &amp;&amp; ($_FILES["file"]["size"] &lt; 100000)//Approx. 100kb files can be uploaded.
      &amp;&amp; in_array($file_extension, $validextensions)) {
          if ($_FILES["file"]["error"] &gt; 0){
              echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br/&gt;&lt;br/&gt;";
          }else{
              if (file_exists("http://www.***/webtools/ondequemvaiver/agora/img/" . $_FILES["file"]["name"])){
                  echo $_FILES["file"]["name"] . " &lt;span id='invalid'&gt;&lt;b&gt;already exists.&lt;/b&gt;&lt;/span&gt; ";
              }else{
                  $sourcePath = $_FILES['file']['tmp_name']; // Storing source path of the file in a variable
                  $targetPath = "http://www.***/webtools/ondequemvaiver/agora/img/".$_FILES['file']['name']; // Target path where file is to be stored
  
                  move_uploaded_file($sourcePath,$targetPath) ; // Moving Uploaded file
  
  
                  echo "&lt;span id='success'&gt;Image Uploaded Successfully...!!&lt;/span&gt;&lt;br/&gt;";
                  echo "&lt;br/&gt;&lt;b&gt;File Name:&lt;/b&gt; " . $_FILES["file"]["name"] . "&lt;br&gt;";
                  echo "&lt;b&gt;Type:&lt;/b&gt; " . $_FILES["file"]["type"] . "&lt;br&gt;";
                  echo "&lt;b&gt;Size:&lt;/b&gt; " . ($_FILES["file"]["size"] / 1024) . " kB&lt;br&gt;";
                  echo "&lt;b&gt;Temp file:&lt;/b&gt; " . $_FILES["file"]["tmp_name"] . "&lt;br&gt;";
              }
          }
      }else{
          echo "&lt;span id='invalid'&gt;***Invalid file Size or Type***&lt;span&gt;";
      }
  }
  ?&gt;
  </code></pre>