Page 1 of 1

Some trouble posting files & updating mysql with PHP

Posted: Wed Jul 04, 2007 6:25 am
by v1ruz666
Hi all,

I'm slightly new to PHP and I'm having some trouble with my PHP code. I'm sending three variables(2 voice recordings & a number) from a VXML form to my PHP, which I then want to deposit the recordings into relevant wav files and update a mysql database with the directory path of the wav files and the number from the vxml.

Here's my PHP code:

Code: Select all

<?php

header('Content-type: application:voicexml+xml; charset=iso-8859-1');
header('Content-Encoding: iso-8859-1');

echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
echo "<vxml version=\"2.1\" xmlns=\"http://www.w3.org/2001/vxml\" xml:lang=\"en-GB\">";
echo "<property name=\"inputmodes\" value=\"dtmf\"/>";
echo "<form>";
echo "<block>";

$msg = "";
$msg2 = "";
$code = 1;
$wavName = "";
$wavAudition = "";
$number = "";

$tmpName=$HTTP_POST_FILES['rec_name']['tmp_name'];

if (is_uploaded_file($tmpName)) {
	$wavName = "///Auditions/name/".date("YmdHis").".wav";
	copy($tmpName, sprintf("%s", $wavName));
	$msg = "audio saved";
	echo "saved name";

} else {
	$code = 0;
	$msg = "unable to save audio";
	echo "not saved";
}

$tmpAudition=$HTTP_POST_FILES['rec_audition']['tmp_name'];

if (is_uploaded_file($tmpAudition)) {
	$wavAudition = "///Auditions/audition/".date("YmdHis").".wav";
	copy($tmpAudition, sprintf("%s", $wavAudition));
	$msg2 = "audio saved";
	echo "saved audition";

} else {

	$code = 0;
	$msg2 = "unable to save audio";
	echo "not saved";
}

$tmpNumber = $_POST['contact_number'];

if (is_uploaded_file($tmpNumber)) {

	copy($tmpNumber, sprintf("%s", $number);

}

$con = mysql_connect("[i]local host[/i]","[i]username[/i]","[i]password[/i]");
if (!$con) {

  die('Could not connect: ' . mysql_error());

}

mysql_select_db("[i]database name[/i]", $con);

$callDate = date("Ymd");
$callTime = date("His");

$sql="INSERT INTO Caller (calContactDir, calContactNum, calAuditionDir, calDate, calTime)
VALUES
('$wavName','$number','$wavAudition', '$callDate', '$callTime')";

if (!mysql_query($sql,$con)) {

  die('Error: ' . mysql_error());

}

$sql="SELECT calUniqueID FROM Caller WHERE calContactDir = '$wavName'";

$uniqueID = mysql_query($sql,$con);

mysql_close($con);

echo "<audio src=\"file:///170.wav\" maxage=\"0\"/>";
echo "<prompt>$callDate</prompt>";
echo "<audio src=\"file:///171.wav\" maxage=\"0\"/>";
echo "<prompt>$uniqueID</prompt>";
echo "<goto next=\"file:///Audition_test.vxml#closing\"/>";

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

?>
I'm submitting the variables via the following line of code:

Code: Select all

<submit next="submit.php" namelist="rec_name rec_audition contact_number" enctype="multipart/form-data"/>
My problem is this:

The audition variable gets saved in a wav file, but not the name variable. Also, I have to comment out the tmpNumber section otherwise I get a "NOT ALLOWED IN PROLOG"

Please ignore the parts of the code in italics (I have to remove that data for business reasons).

If anyone could shine some light on this, it would be greatly appreciated.

Thanx!

Posted: Wed Jul 04, 2007 7:16 am
by idevlin
Why have you put italicised tags around the mysql_connect? Am sure that's not allowed, although perhaps I'm wrong?

Code: Select all

$con = mysql_connect("[i]local host[/i]","[i]username[/i]","[i]password[/i]"); 

Posted: Wed Jul 04, 2007 7:29 am
by v1ruz666
Hi idevlin,

I omitted the data in local host, username and password for security reasons. Didn't want to post my companies database information out in the open for everyone to see 8O

Posted: Wed Jul 04, 2007 7:34 am
by undecided name 01
That's phpBB's bb code.

Posted: Wed Jul 04, 2007 9:23 am
by ghadacr
v1ruz666 wrote:Hi idevlin,

I username and password for security reasons. Didn't want to post my companies database information out in the open for everyone to see 8O
I suggest you seprating that part away from this script for "security" reasons, Also you dont need to re write all the connection tags again. All you need to do is use Include or require..... Saves time, i suppose.....

Posted: Wed Jul 04, 2007 9:38 am
by volka
v1ruz666 wrote:$HTTP_POST_FILES
this variable may or may not be available anymore.
What does

Code: Select all

<?php
echo 'version: ', phpversion(), "<br />\n";
echo 'sapi: ', php_sapi_name(), "<br />\n";
echo 'register_globals: ', get_cfg_var('register_globals') ? 'on':'off', "<br />\n";
echo 'register_long_arrays: ', get_cfg_var('register_long_arrays') ? 'on':'off', "<br />\n";
echo '<pre>extensions:'; print_r(get_loaded_extensions()); echo "</pre>\n";
print?

Posted: Fri Jul 06, 2007 4:40 am
by v1ruz666
Hi Volka!

Thanks for replying.

Here's what that code prints out:

version: 4.4.1-pl3-gentoo
<br/>

sapi: apache2handler
<br/>

register_globals: off
<br/>

<pre>
extenstions:Array
(
[0] => xml
[1] => varfilter
[2] => standard
[3] => snmp
[4] => session
[5] => pspell
[6] => pcre
[7] => mysql
[8] => mhash
[9] => mcrypt
[10] => mbstring
[11] => imap
[12] => gmp
[13] => gettext
[14] => gd
[15] => domxml
[16] => dba
[17] => curl
[18] => bz2
[19] => zlib
[20] => openssl
[21] => apache2handler
)
</pre>

Still having some trouble

Posted: Tue Jul 10, 2007 4:57 am
by v1ruz666
Hi all,

I've managed to sort out most of the problems I was having with my script (seems HTTP_POST_FILES has been deprecated) although I'm still having some trouble getting name to save. The code is exactly the same as it is for audition. Please help me out here.

Here's my php code:

Code: Select all

$tmpName=$_FILES['rec_name']['tmp_name'];

if (is_uploaded_file($tmpName)) {
	$wavName = date("YmdHis").".wav";
	$fileName = "/name/".$wavName;
	copy($tmpName, sprintf("%s", $fileName));
	$msg = "audio saved";
	echo "saved name";

} else {
	$code = 0;
	$msg = "unable to save audio";
	echo "not saved";
}

$tmpAudition=$_FILES['rec_audition']['tmp_name'];

if (is_uploaded_file($tmpAudition)) {
	$wavAudition = date("YmdHis").".wav";
	$fileAud = "/audition/".$wavAudition;
	copy($tmpAudition, sprintf("%s", $fileAud));
	$msg2 = "audio saved";
	echo "saved audition";

} else {

	$code = 0;
	$msg2 = "unable to save audio";
	echo "not saved";
}
The variables get submitted with the following line of code:

Code: Select all

<submit next="submit.php" enctype="multipart/form-data" namelist="rec_name rec_audition" method="post" maxage="0"/>
Any help would be greatly appreciated.

Thank you.

Posted: Tue Jul 10, 2007 6:10 am
by v1ruz666
Never mind guys. Got it sorted out. The problem was actually in the vxml.

Thank you anyways :D