title: jQuery post method to send input file to PHP on change
body: <p>As I understood $.ajax() is equivalent to $.post(). I am trying to use $.post to submit input file to PHP script. The purpose is to upload the image once the user browse and choose it.</p>
  
  <p>I am trying to use something simple like this:</p>
  
  <pre><code>$(document).ready(function(){
  $("input:file").change(function(){
  $("#fileName").data($(this).val());
  $.post( "upload.php", { fileName: $(this).val() }, function( data ) {
  $( ".div1" ).html( data );
  }); 
  }); 
  }); 
  </code></pre>
  
  <p>When I echo <code>$_POST["fileName"]</code> it shows: </p>
  
  <blockquote>
    <p>C:\fakepath\imag-name.jpg</p>
  </blockquote>
  
  <p>When I try to get the file data using <code>basename($_FILES["fileName"]["name"])</code>
  I get this error: </p>
  
  <blockquote>
    <p>Notice: Undefined index: fileName ...... etc</p>
  </blockquote>
  
  <p>Any advice or solution is appreciated.
  Thank you in advance.</p>