Jump to content

VXML/PHP issue


Recommended Posts

Hello,

 

I'm having a bit of a nightmare trying to get this to work. The script is supposed to create a .wav file and then upload it to a directory on my server. The basic script is a VXML script, but the VXML part (record_comment.php) has been tested and seems to be doing what it's supposed to; when it gets to the PHP upload script (upload_comment.php) it just keeps telling me that it's "unable to save comment". I have set both the directories to have 0777 permissions (the directory containing the scripts and the directory which will contain the audio file). Can anyone suggest anything else that I could try to get this working please.

 

This is the PHP/VXML page which is supposed to post to upload_comment.php:

 

<=== record_comment.vxml ===>

 

<?php

 

// record weblog comment

// modeled after studio.tellme.com/vxml2/ref/elements/record.html

 

header("Content-Type: text/xml");

 

// if you have the ability to do so, set $highest to the highest entry

// number. Otherwise, you'll want to take out all the parts that refer

// to $highest.

 

$highest = HIGHEST_ENTRY_NUMBER;

 

print "<?xml version=\"1.0\"?>";

?>

<vxml version="2.0">

 

<!-- prepare variable to specify the entry to attach the comment to. -->

<var name="entryID" expr="0" />

 

<form id="Choose">

<field name="id" >

 

<!-- load grammars so user can speak or type the entry number -->

<grammar>TM_DTMF_DigitString</grammar>

<grammar>NATURAL_NUMBER_THRU_9999</grammar>

 

<prompt>

<audio>Press 0 to leave a general comment or type the number of a

specific entry (between 1 and <? print $highest; ?>).</audio>

</prompt>

 

<catch event="noinput nomatch">

<audio>sorry. i didn't get that. Please press 0 or an entry number

between 1 and <? print $highest; ?>.</audio>

<reprompt/>

</catch>

 

<filled>

<log>Comment ID spoken or typed = <value expr="id"/>.</log>

<assign name="entryID" expr="id" />

<goto next="#record_blog_entry"/>

</filled>

</field>

</form>

 

<form id="record_blog_entry">

 

<!-- maximum entry length is set at 240 seconds (3 minutes) -->

<record name="blog_comment" maxtime="240s" dtmfterm="true" beep="true">

<prompt>

<audio>At the tone, record your comment (limit 3 minutes).

When you're done, press pound.</audio>

</prompt>

 

<!-- if the user doesn't say anything within finalsilence, catch the noinput -->

<noinput>Sorry. I didn't hear you. Now returning to the menu.

<goto next="./menu.php"/>

</noinput>

 

<filled>

<log>recording size = <value expr="blog_comment$.size"/> bytes.</log>

<log>recording duration = <value expr="blog_comment$.duration"/>

milliseconds.</log>

<log>dtmf key = <value expr="(blog_comment$.termchar ?

blog_comment$.termchar : 'none')"/></log>

</filled>

</record>

 

<!-- confirm that we should upload the comment -->

<field name="conf">

<prompt>

<audio>Press 1 or say yes to post this comment.</audio>

<audio>Otherwise, press 2 or say cancel.</audio>

</prompt>

 

<grammar>

<![CDATA[

[

[dtmf-1 yes ok yeah] {<conf "yes">}

[dtmf-2 cancel no nope] {<conf "cancel">}

]

]]>

</grammar>

 

<catch event="noinput">

<audio>Recording canceled. Now returning you to the main menu.</audio>

<goto next="./menu.php"/>

</catch>

 

<catch event="nomatch">

<audio>Please say yes or cancel.</audio>

</catch>

 

<filled>

<if cond="'cancel' == conf">

<goto next="./menu.php"/>

</if>

<!-- else continue on to uploading the comment to weblog -->

</filled>

</field>

 

<!-- upload voice comment to weblog -->

<subdialog name="oResult"

src="http://localhost/HitOrMiss/upload_comment.php"

namelist="entryID blog_comment" method="post">

<filled>

<if cond="oResult.code">

<audio>Comment sent</audio>

<log><value expr="oResult.msg"/></log>

<else/>

<audio>Error sending comment</audio>

<log><value expr="oResult.msg"/></log>

</if>

</filled>

</subdialog>

 

<block>

<break time="200ms"/>

<audio>Now back to the main menu.</audio>

<goto next="./menu.php"/>

</block>

 

</form>

</vxml>

 

 

<=== End record_comment.php ===>

 

...and this script uploads the file:

 

<=== upload_comment.php ===>

 

<?php

 

// upload comment to weblog

// modeled after code by Scott Schreckengaust /

// studio.tellme.com/vxml2/ref/elements/record.html

 

header("Content-Type: text/xml");

header("Pragma: no-cache");

 

// load soundfile

$tmpFile=$HTTP_POST_FILES['blog_comment']['tmp_name'];

 

// check to see if this is a general or specific comment

if ($entryID == 0)

{

$commentWavFilePrefix = "general_";

}

else

{

// you'll want to set the pad length to match the entry ID length

// of your weblog system (if the entryID needs to be padded and isn't already

$commentWavFilePrefix = str_pad($entryID, 6, "0", STR_PAD_LEFT)."_";

}

 

if (is_uploaded_file($tmpFile))

{

// make up a file name using the current time

$wavfile = $commentWavFilePrefix.date("Y-m-d-His").".wav";

 

// set the path to where the file should be saved on your server

// make sure permissions to this director are set

$wavpath = "/HitOrMiss_audio/".$wavfile;

 

move_uploaded_file ($tmpFile, sprintf("%s",$wavpath));

chmod (sprintf("%s",$wavpath), 0744);

 

$code = 1;

$msg = "comment saved locally";

 

// if comment is for a specific entry, make a comment pointing to the audio file

if ($entryID > 0)

{

// write you own code to create a comment in your weblog pointing

// to the audio file

// Ex. the comment may read: <a href="http://localhost/HitOrMiss_Audio/$wavfile">audio comment</a>

 

$msg = "comment posted to blog";

}

 

// send an email to the blog adminstrator letting them know a comment has been sent

$message = "A new voice comment has been saved.\n";

mail("[email protected]", "Voice Comment", $message);

}

else

{

$code = 0;

$msg = "unable to save comment";

}

 

// display subdialog response for record_comment.php

 

echo "<?xml version=\"1.0\"?>\n";

echo "<vxml version=\"2.0\">\n";

echo "<form>\n";

echo "<var name=\"code\" expr=\"$code\"/>\n";

echo "<var name=\"msg\" expr=\"'$msg'\"/>\n";

echo "<block>\n";

echo "<return namelist=\"code msg\"/>\n";

echo "</block>\n</form>\n</vxml>\n";

?>

 

<=== End upload_comment.php ===>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/43100-vxmlphp-issue/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.