I've written code to submit audio file to server but i'm not getting success response from ajax. here is the html
<input type='file' name='music' id='default_files'>
<div id='refpic' value='Save'style=' border : 1px solid #73963e;' >Save</div>
here is the ajax call code on button click
<script type="text/javascript">
$('#refpic').click(function(){
var formdata = new FormData();
var file = $('#default_files').prop('files')[0];
formdata.append("refaudio", file);
formdata.append("id", '1');
$.ajax
({
url: 'change_image_audio.php',
data: formdata,
type: 'post',
success: function(result)
{
alert('ok');
}
});
});
</script>
here is my php code
<?php
$id=$_POST['id'];
$target_path = "sounds/";
$target_path = $target_path . basename($_FILES['refaudio']['name']);
if(move_uploaded_file($_FILES['refaudio']['tmp_name'], $target_path)){
echo "success";
}
?>
Please help me to find where i'm doing wrong. Any help would be much appreciated. Thank you