Voicexml:<record>以$ _POST而非$ _FILES </record>的形式提交

时间:2013-09-25 14:50:29

标签: php vxml

我在下面的voicexml中的帖子以

的形式到达我的php脚本
$ _POST['SOURCEADDR'] & $ _POST['recMsg']

我的服务器配置是否需要执行以启用$_FILES[]? 当我从html网页发帖时,我有相同的脚本正常工作。

<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 个答案:

答案 0 :(得分:1)

您在VoiceXML中指定将使用哪种类型的HTTP请求将录制的音频发送到服务器。

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

这是将音频文件发送到服务器的典型方法。您没有在服务器上指定音频的发送方式。

在此Voxeo article中使用此类型的提交时,有一个关于如何在PHP中检索音频的示例。查看PHP示例的页面底部。这是示例代码。

<?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>";
?>

根据Voxeo的这个例子,它应该返回一种HTTP_POST_FILES,而不是_FILES []。 HTTP_POST_FILES是通过HTTP POST方法上传到当前脚本的项的关联数组。