I am working with an AJAX function that looks like this:
reader.onload = function(event){
var fd = new FormData();
var Name = encodeURIComponent('audio_recording_' + new Date().getMinutes() + '.wav');
console.log("name = " + Name);
fd.append('fname', Name);
fd.append('data', event.target.result);
$.ajax({
type: 'POST',
url: 'upload.php',
data: fd,
processData: false,
contentType: false,
success: function(data){
//console.log(data);
$.ajax({
type: 'POST',
url: 'readFile.php',
data: {"fileName":fileName},
success: function(data){
console.log(data);
}
});
}
});
};
First question: How can I retrieve the data from the second success function to utilize it later in the code?
Second question: The data being retrieved is an audio file. Is there a specific method to obtain audio data, or can we retrieve it in the same way as other data types? In my PHP server-side script for the second AJAX request, I am reading an audio file and need to access its data. I have attempted a basic file open and read contents approach. Will this work for audio files?
Server-side code:
<?php
$fileName=$_POST["fileName"];
$dh = opendir('upload/');
$contents = file_get_contents('C:/wamp/www/JSSoundRecorder/upload/'.$fileName);
// echo $contents;
echo $fileName;