I am really happy with the priceless suggestions that you all gave me last time.i really thank you all. But this time i am trying to upload an file using ajax. As the user select the file in the browse window, it straight away uploads the image. Please help me with this too. Thank you all.
This is my code:
function upd(str)
{
$.ajax({
type:'post',
url:'upld.php',
datatype:'php',
data:'fname='+str,
success:function(responce)
{
alert("Uploaded");
}
});
}
</script>
</head>
<body>
<form action="upd.php" method="post" enctype="multipart/form-data">
<input type="file" name="namefile" id="namefile" onSelect="upd(this.value)">
</form>
and my upld.php contains the following code:
<?php
$target="uploads/";
$target=$target.basename($_FILES['file']["name"]);
move_uploaded_file($_FILES['file']["tmp_name"],$target);
echo basename($_FILES["file"]["name"])."File Uploaded";
?>
FormDataAPI. mdn.beonex.com/en/DOM/XMLHttpRequest/FormData/…base64encoding and send a nice and long string to your backend :) Anyway, you can use systems like uploadify (uses flash) to do it