I'm working on an online experiment (using the jsPsych library) where participants (each with a code number randomly assigned by the script) will record a number of .wav files. I then want to upload to the server with names that include the participant's code number and the item number associated with that recording. Each participant will be creating something like 36 different short .wav files.
It looks like recorderjs and recordermp3.js are what I need to record the audio on the browser side (see RecorderJS uploading recorded blob via AJAX), but I'm having difficulty finding the information I need to create a PHP script that will save a file of unknown file name.
Here's the relevant javascript:
function stopRecording(subjectID, item_number) {
recorder && recorder.stop();
console.log('Stopped recording.');
recorder && recorder.exportWAV(function(blob) {
var xhr=new XMLHttpRequest();
xhr.onload=function(e) {
if(this.readyState === 4) {
console.log("Server returned: ",e.target.responseText);
}
};
var fd=new FormData();
fd.append(subjectID + item_number + ".wav", blob);
xhr.open("POST","upload_wav.php",true);
xhr.send(fd);
};
recorder.clear();
}
And here's what I have so far for PHP:
<?php
$target_dir = 'audio/';
$target_file=$target_dir . basename[$_FILES["fileToUpload"]["name"];
move_uploaded_file($_FILES[“fileToUpload”][“tmp_name”], $target_file);
chmod($target_file,0755);
?>
My question is very similar to Saving WAV File Recorded in Chrome to Server and HTML5 & getUserMedia - Record Audio & Save to Web Server after Certain Time but different in that I don't know what the filename of the uploaded file will be and I want to use PHP (mostly because I was told to). What can I use instead of "fileToUpload" in the php script to get this script to work for any .wav file that is sent to it?
In case you haven't already guessed I have learned everything in know about javascript and PHP in the last month or so, so please be gentle with the n00b. I have looked in various PHP tutorials and documentations but just don't seem to be finding what I'm looking for there. Code would be most appreciated.