title: Using PHP to save file with unknown file name
body: <p>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.</p>
  
  <p>It looks like recorderjs and <a href="http://audior.ec/blog/recording-mp3-using-only-html5-and-javascript-recordmp3-js/" rel="nofollow noreferrer">recordermp3.js</a> are what I need to record the audio on the browser side (see <a href="https://stackoverflow.com/questions/15014638/recorderjs-uploading-recorded-blob-via-ajax">RecorderJS uploading recorded blob via AJAX</a>), but <strong>I'm having difficulty finding the information I need to create a PHP script that will save a file of unknown file name</strong>.</p>
  
  <p>Here's the relevant javascript:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function stopRecording(subjectID, item_number) {
      recorder &amp;&amp; recorder.stop();
      console.log('Stopped recording.');
      recorder &amp;&amp; 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();
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>And here's what I have so far for PHP:</p>
  
  <pre><code>&lt;?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);
  ?&gt;
  </code></pre>
  
  <p>My question is very similar to <a href="https://stackoverflow.com/questions/16616010/saving-wav-file-recorded-in-chrome-to-server?rq=1">Saving WAV File Recorded in Chrome to Server</a> and <a href="https://stackoverflow.com/questions/16810450/html5-getusermedia-record-audio-save-to-web-server-after-certain-time">HTML5 &amp; getUserMedia - Record Audio &amp; Save to Web Server after Certain Time</a> 
  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?</p>
  
  <p>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.</p>