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.
I am trying to use something simple like this:
$(document).ready(function(){
$("input:file").change(function(){
$("#fileName").data($(this).val());
$.post( "upload.php", { fileName: $(this).val() }, function( data ) {
$( ".div1" ).html( data );
});
});
});
When I echo $_POST["fileName"]
it shows:
C:\fakepath\imag-name.jpg
When I try to get the file data using basename($_FILES["fileName"]["name"])
I get this error:
Notice: Undefined index: fileName ...... etc
Any advice or solution is appreciated. Thank you in advance.