1

My posts from the voicexml below arrives my php script as a

$ _POST['SOURCEADDR'] & $ _POST['recMsg']

Is there something I have to do at my server's configuration to enable $_FILES[]? I have this same script working properly when I post from a html web page.

<form id="record">
<record name="recMsg" beep="true" maxtime="120s" finalsilence="5000ms" dtmfterm="true" type="audio/basic">
<prompt>
<audio src="sounds/RECORD_AFTER_BEEP.au"/><audio src="sounds/COMEDY_WARRANT.au"/>
</prompt>
<noinput>
<audio src="sounds/NOTHING_RECORDED.au"/>
</noinput>
<filled>
<submit next="saveRecording.php" namelist="SOURCEADDR recMsg" method="post" enctype="multipart/form-data"/>
</filled>
</record>
</form>

====== PHP Script =====
<?
if ($_FILES){
$ftype = $_FILES["recMsg"]["type"];
$fsize = $_FILES["recMsg"]["size"];
$ftemp = $_FILES["recMsg"]["tmp_name"];
$phone = $_REQUEST["SOURCEADDR"];
$fname = "rec_".$phone."_".date("Ymdgis").".au"; //$_FILES['recMsg']['name'];
flog("debug.log", "Got: $ftype | $fsize | $phone | $fname");
}else{
$out = flog("debug.log", "no $ _FILES array");
echo '<?xml version="1.0" encoding="ISO-8859-1"?><vxml version="2.0"><form id="main">
<block>'.'ERROR POST'.'</block></form></vxml>';
exit;
}
?>

1 Answers1

1

You specify in the VoiceXML what type of HTTP request will be used to send the recorded audio to the server.

<submit expr=example.php method="post" namelist="rec" enctype="multipart/form-data"/>

This is the typical method for sending audio files to the server. You do not specify on the server how the audio is sent.

There is an example on how to retrieve the audio in PHP when using this type of submit in this Voxeo article. Look at the bottom of the page for the PHP example. Here is the example code.

<?PHP
header('Cache-Control: no-cache');

error_reporting (0);

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo "<vxml version=\"2.0\">";

echo "<form id=\"main\">";
echo "<block>";

if ($HTTP_POST_FILES) {
  foreach ($HTTP_POST_FILES as $key => $value) {
    foreach ($value as $Filename) {

      if (strpos($Filename, "WINNT")) { $ServerSide = $Filename; }
      if (strpos($Filename, ".wav"))  { $ClientSide = $Filename; }
    }  // for each statement

    $ServerSide = str_replace("\\\\", "/", $ServerSide);

    if (!copy($ServerSide, "c:/audio-storage/temp.wav")) {
      echo "Could not save filename: " . $ServerSide;
    } // if statement
    else {
      echo "Successfully saved filename: " . $ServerSide;
    }  // else statement

  }  // for each statement
}  // if statement

echo "</block>";
echo "</form>";
echo "</vxml>";
?>

According to this example from Voxeo it should return a type of HTTP_POST_FILES, not _FILES[]. HTTP_POST_FILES is an associative array of items uploaded to the current script via the HTTP POST method.

Kevin Junghans
  • 17,475
  • 4
  • 45
  • 62
  • Thank you Kevin, I appreciate your response. I did follow the examples as I've shown above. But the audio file gets to my php script in the wrong key. While I'm expecting it in the $_FILES[] array, I'm getting it in the $_POST array. Is there something above that I need to change? – user2815158 Sep 26 '13 at 08:42
  • Take a look at my updated answer. It looks like you should be getting a HTTP_POST_FILES. – Kevin Junghans Sep 26 '13 at 12:42