Voicexml: <record> submiting as $_POST instead of $_FILES - php

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

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.

Related

I've uploaded an XML file and want to be able to filter data, then save it for the user

this is my first Stack question. Please provide some criticism for the future posts I plan to do! I'm pretty new at PHP and feel I've scanned the PHP docs multiple times now trying to get a push in the right directions.
The goal of my current project is to upload an XML file, allow a user to filter that file by keywords and/or sections, save the new updated version and allow the user to download it.
I've got the upload an xml file and show it to the user. I'm confused on the next step of searching through this file, how do I access the file I've uploaded again? Is it a scoping issue or can I access the current variable?
Here's some code that shows you where I'm at currently. Please let me know if I'm missing anything appreciate ya.
This is the upload function.
<?php
// header('Content-type: text/xml');
if(isset($_POST['submit'])) {
$filterSection = array(
'path',
'id',
'title',
);
$file = $_FILES['file'];
$fileName = $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('xml');
if (file_exists($fileTmpName)) {
$xml = file_get_contents($fileTmpName);
// $xml = simplexml_load_file($fileTmpName, 'SimpleXMLElement', LIBXML_NOCDATA);
require_once('function1.php');
function1($xml);
}
else {
echo "There was an error uploading your file";
}
} else {
echo "You cannot upload files of this type.";
}
?>
This is function1 which lays out the info in a table.
<?php
function build_table($array) {
echo '<table class="gridtable">';
echo '<tr>';
$oneArray = ($array['item'][0]);
foreach($oneArray as $key=>$value){
echo '<th>' . htmlspecialchars($key) . '</th>';
// echo "<form action='checkbox.php' method='get'> <input type='checkbox' name='formSubmit' value='Submit' /></form> ";
}
echo '</tr>';
echo '<tr>';
foreach($array['item'] as $item) {
echo '</tr>';
foreach($item as $key2=>$value2){
if(is_array($value2)) {
if(empty($value2)) {
//I feel this is extremely wrong line of code? Cant get the </variableclosingtag> to work as requested.
echo '<td>' . $key2 . '</td>';
} else {
foreach($value2 as $key3=>$value3) {
if(is_array($value3)) {
echo '<td>' . implode($value3) . '</td>';
} else {
echo '<td>' . $value3 . '</td>';
}
}
}
} else {
echo '<td>' . $value2 . '</td>';
}
}
}
echo '</table>';
}
function function1($xml) {
$data = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
$json_string = json_encode($data);
$dataArr = json_decode($json_string, true);
build_table($dataArr);
print_r(build_table($dataArr), 'HEREHELP');
}
?>
I know this is a general question, I'm looking for a general answer. I don't want someone to write code for me, but push me in the right direction.
Appreciate yall.
XML FILE Being uploaded (All files should be the same for this project).
-<items>
-<item>
<path>https://www.companyb.com/content/dam/competition/datacenter/companyb-foobar-dc-persistent-memory-review-response-guide-.pptx</path>
<id>a1021019</id>
-<title>
-<![CDATA[Company B foobar DC Persistent Memory Review Response Guide]]>
</title>
-<description>
-<![CDATA[Company B foobar DC Persistent memory Review Response Guide details the review landscape and positioning vs DRAM & NVDIMMs. Content includes Company B Internal only material]]>
</description>
-<keywords>
-<![CDATA[foobar,Persistent,Memory, Samsung,Apache Pass, AEP, Crystal Ridge]]>
</keywords>
<filetype>pptx</filetype>
<filename>companyb-foobar-dc-persistent-memory-review-response-guide-.pptx</filename>
<binaryfilesize>3.60MB</binaryfilesize>
<thumbnailViewPath>/content/dam/competition/datacenter/companyb-foobar-dc-persistent-memory-review-response-guide-.pptx.renditions.cq5dam.thumbnail.319.319.png</thumbnailViewPath>
<detailViewPath>/content/dam/competition/datacenter/companyb-foobar-dc-persistent-memory-review-response-guide-.pptx.renditions.cq5dam.web.1280.1280.jpeg</detailViewPath>
<publishdate>2018-11-13</publishdate>
<expiredate>2020-11-13</expiredate>
<createddate>2018-11-14</createddate>
<createdby>admin</createdby>
<lastmodifieddate>2018-12-14</lastmodifieddate>
<assetOwner>Syona Someone</assetOwner>
<assetOwnerEmail>syona.someone#companyb.com</assetOwnerEmail>
<secondaryOwner/>
<secondaryOwnerEmail/>
<assetExternalURL/>
<linkurl/>
<numPages>1</numPages>
<contentType/>
<usagetype>etma759c80e8b7a4081b8f8f7e3376191f3</usagetype>
-<languages>
<language>English</language>
</languages>
<geos/>
<products/>
<environment>prod</environment>
<clients/>
-<datacenters>
<datacenter>DAM Datacenter|Competition|Other</datacenter>
</datacenters>
<iots/>
<pncproducts/>
<featured/>
</item>
-<item>
<path>https://www.companyb.com/content/dam/competition/datacenter/nda-companyb-mountain-lake-vs-amat-france-review-analysis-networking-comms.pdf</path>
<id>a1027038</id>
-<title>
-<![CDATA[CLX Vs AMAT france Comms Review analysis ]]>
</title>
-<description>
-<![CDATA[france Vs CLX, ~10 WL including EPC ]]>
</description>
-<keywords>
-<![CDATA[AMAT Networking Comms mountain Lake EPC ]]>
</keywords>
<filetype>pdf</filetype>
<filename>nda-companyb-mountain-lake-vs-amat-france-review-analysis-networking-comms.pdf</filename>
<binaryfilesize>1.60MB</binaryfilesize>
<thumbnailViewPath>/content/dam/competition/datacenter/nda-companyb-mountain-lake-vs-amat-france-review-analysis-networking-comms.pdf.renditions.cq5dam.thumbnail.319.319.png</thumbnailViewPath>
<detailViewPath>/content/dam/competition/datacenter/nda-companyb-mountain-lake-vs-amat-france-review-analysis-networking-comms.pdf.renditions.cq5dam.web.1280.1280.jpeg</detailViewPath>
<publishdate>2019-06-20</publishdate>
<expiredate>2021-06-20</expiredate>
<createddate>2019-06-20</createddate>
<createdby>admin</createdby>
<lastmodifieddate>2019-06-20</lastmodifieddate>
<assetOwner>Praveen Menon</assetOwner>
<assetOwnerEmail>praveen.k.menon#companyb.com</assetOwnerEmail>
<secondaryOwner/>
<secondaryOwnerEmail/>
<assetExternalURL/>
<linkurl/>
<numPages>1</numPages>
<contentType/>
<usagetype>etmc4c5e7132748472e9818c2966e681da5</usagetype>
-<languages>
<language>English</language>
</languages>
-<geos>
<geo>Asia Pacific</geo>
<geo>EMEA</geo>
<geo>Latin America</geo>
<geo>North America</geo>
<geo>People's Republic of China</geo>
</geos>
<products/>
<environment>prod</environment>
<clients/>
-<datacenters>
<datacenter>DAM Datacenter|Competition|Network Infrastructure</datacenter>
<datacenter>DAM Datacenter|Competition|AMAT x86</datacenter>
</datacenters>
<iots/>
<pncproducts/>
-<featured>
<featured>DAM Datacenter : Competition / Network Infrastructure,DAM Datacenter : Competition / AMAT x86,</featured>
</featured>
</item>

HTML using a PHP script

im new in php programming and ive a problem recently. I have 1 html page with a Search Box and a php script using for grep in a specific file on local host. This is what i want, when a user type string of char and click on enter that send a POST to modify my php var $contents_list, and grep all filename where the string is found.
<?php
$contents_list = $_POST['search'];
$path = "/my/directory/used/for/grep";
$dir = new RecursiveDirectoryIterator($path);
$compteur = 0;
foreach(new RecursiveIteratorIterator($dir) as $filename => $file) {
$fd = fopen($file,'r');
if($fd) {
while(!feof($fd)) {
$line = fgets($fd);
foreach($contents_list as $content) {
if(strpos($line, $content) != false) {
$compteur+=1;
echo "\n".$compteur. " : " . $filename. " : \n"."\n=========================================================================\n";
}
}
}
}
fclose($fd);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<form action="page2.php" method="post">
<INPUT TYPE = "TEXT" VALUE ="search" name="search">
</form>
</body>
And when i go to my html page and type text in searchbar, that redirect me to my php script "localhost/test.php" and i have 500 internal error.
So I want:
To see result of the php script on the same html page, but i dont know how to do that :/
And if the previous filename return was same like previous result, dont print it, to avoid double result.
I hope its clear and youve understand what i want to do, so thanks for the people who want to help me <3
My recommendations:
Combine the code into the single index.php file for simplicity
Separate logic for search and output to achieve clean separation of duties
Add helper text such as nothing found or enter text
index.php content:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<form action="index.php" method="post">
<input type="text" placeholder="search" name="search">
</form>
<?php
// Check if the form was submitted.
if (isset($_POST['search']) && (strlen($_POST['search'])) > 0) {
$search_line = $_POST['search'];
$path = "/my/directory/used/for/grep";
$dir_content = new RecursiveDirectoryIterator($path);
// Array to store results.
$results = [];
// Iterate through directories and files.
foreach (new RecursiveIteratorIterator($dir_content) as $filename => $file) {
$fd = fopen($file, 'r');
if ($fd) {
while (!feof($fd)) {
$file_line = fgets($fd);
if (strpos($file_line, $search_line) !== FALSE) {
$results[] = $filename;
}
}
fclose($fd);
}
}
// Output result.
echo "<pre>";
if ($results) {
foreach ($results as $index => $result) {
echo ($index + 1) . " :: $result\n";
}
}
else {
echo "Nothing found!";
}
echo "</pre>";
}
else {
// When nothing to search.
echo "<pre>Enter something to search.</pre>";
}
?>
</body>
</html>

PHP, using $_FILES and $_POST at the same time

I have a problem in using $_FILES and $_POST at the same the because I have a form to upload an image and some data bus when I use one of them it works but when I used the other one id doesn't work.
my code is :
<?php
include 'debugging.php';
//phpinfo();
echo '<br />';
echo '<h1>Image Upload</h1>';
//create a form with a file upload control and a submit button
echo <<<_END
<br />
<form method='post' action='uplaodex.php' enctype='multipart/form-data'>
Select File: <input type='file' name='picName' size='50' />
name: <input type='text' name='usName' size='50' />
username : <input type='text' name='usUsername' size='50' />
pass: <input type='password' name='usPass' size='50' />
email: <input type='text' name='usEmail' size='50' />
<br />
<input type='submit' value='Upload' />
<input type="hidden" name="submit" value="1" />
</form>
<br />
_END;
//above is a special use of the echo function - everything between <<<_END
//and _END will be treated as one large echo statement
//$_FILES is a PHP global array similar to $_POST and $_GET
if (isset($_FILES['picName'])and isset($_POST['submit'])) {
//we access the $_FILES array using the name of the upload control in the form created above
//
//create a file path to save the uploaded file into
$name = "images//" . $_FILES['picName']['name']; //unix path uses forward slash
//'filename' index comes from input type 'file' in the form above
//
//move uploaded file from temp to web directory
if (move_uploaded_file($_FILES['picName']['tmp_name'], $name)) {
// Create the file DO and populate it.
include 'Do_profile.php';
$file = new Do_profile();
//we are going to store the file type and the size so we get that info
$type = $_FILES['picName']['type'];
$size = $_FILES['picName']['size'];
$usName = trim($_POST['usName']);
$usUsername = trim($_POST['usUsername']);
$usPass = trim($_POST['usPass']);
$usEmail = trim($_POST['usEmail']);
$file->FileName = $name; //$name is initialised previously using $_FILES and file path
$file->FileSize = $size;
$file->Type = $type;
$file->usName = $usName;
$file->usUsername = $usUsername;
$file->usPass = $usPass;
$file->usEmail = $usEmail;
if ($file->save()) {
//select the ID of the image just stored so we can create a link
//display success message
echo "<h1> Thankyou </h1><p>Image stored successfully</p>";
//this above line of code displays the image now stored in the images sub directory
echo "<p>Uploaded image '$name'</p><br /><img src='$name' height='200' width='200'/>";
//create alink to the page we will use to display the stored image
echo '<br><a href="Display.php?id=' . $fileId . '">Display image ' .
$file->FileName . '</a>';
} else
echo '<p class="error">Error retrieving file information</p>';
}
else {
echo '<p class="error"> Oh dear. There was a databse error</p>';
}
} else {
//error handling in case move_uploaded_file() the file fails
$error_array = error_get_last();
echo "<p class='error'>Could not move the file</p>";
// foreach($error_array as $err)
// echo $err;
}
echo "</body></html>";
?>
I don't know what is the problem, any help??
Everything inside that if (isset($_FILES['picName'])and isset($_POST['submit'])) doesn't work because the superglobal $_FILES is probably not having a key named picName. To check this out, try var_dump-ing the $_FILES, like var_dump($_FILES);
By the output of the var_dump you'd get to know if there is any content inside $_FILES. And if it is populated, just see what the key name is and, access the file by using that key.
But if the array is empty, there may be some mis-configurations in PHP, or APACHE.
One possible fix would be setting file_uploads = On in the ini file for php.
Hope it helps!
You have to validate the size of the file if you want to do an isset. I don't know if this is works, but the better way for do that is check first the size for validate if isset or was send to the server.
Then, in your <form method='post' action='uplaodex.php' enctype='multipart/form-data'> you have to create another PHP file with the name uplaodex.php where you'll send al the data. So, your code with be like the below code following and considering the step 1. This will be your uploadex.php
$name_file = $_FILES['picName']['name'];
$type = $name_file['type'];
$size = $name_file['size'];
$tmp_folder = $name_file['tmp'];
$usName = trim($_POST['usName']);
$usUsername = trim($_POST['usUsername']);
$usPass = trim($_POST['usPass']);
$usEmail = trim($_POST['usEmail']);
if ( $size > 0 ) {
//REMOVE another slash images//
$name = "images/" . $name_file; //unix path uses forward slash
//'filename' index comes from input type 'file' in the form above
//
//move uploaded file from temp to web directory
if ( move_uploaded_file($tmp_folder, $name) ) {
// Create the file DO and populate it.
include 'Do_profile.php';
$file = new Do_profile();
$file->FileName = $name; //$name is initialised previously using $_FILES and file path
$file->FileSize = $size;
$file->Type = $type;
$file->usName = $usName;
$file->usUsername = $usUsername;
$file->usPass = $usPass;
$file->usEmail = $usEmail;
if ($file->save()) {
//USE PRINTF
printf('<h1> Thankyou </h1><p>Image stored successfully</p><br>
<p>Uploaded file: %s</p>. <img src="%s" height="200" width="200" />',
$name_file, $name );
#WHAT IS $fileId? In which moment was define?
//echo '<br><a href="Display.php?id=' . $fileId . '">Display image ' .
$file->FileName . '</a>';
}
else
echo '<p class="error">Error retrieving file information</p>';
}
else {
echo '<p class="error"> Oh dear. There was a databse error</p>';
} //ENDIF OF if (move_uploaded_file($_FILES['picName']['tmp_name'], $name))
} //ENDIF OF if ( $size > 0 )
#ELSE OF YOUR if ( $size > 0 )
else {
//error handling in case move_uploaded_file() the file fails
$error_array = error_get_last();
echo "<p class='error'>Could not move the file</p>";
// foreach($error_array as $err)
// echo $err;
}
I solved the problem, you can't perform $_FILES and $_post at the same time or one of them inside the other.
start with $_Post and then $_FILES and outside the $_FILES run your saving function
thats it

Merge 2 php scripts

I need some help with some php scripting. I wrote a script that parses an xml and reports the error lines in a txt file.
Code is something like this.
<?php
function print_array($aArray)
{
echo '<pre>';
print_r($aArray);
echo '</pre>';
}
libxml_use_internal_errors(true);
$doc = new DOMDocument('1.0', 'utf-8');
$xml = file_get_contents('file.xml');
$doc->loadXML($xml);
$errors = libxml_get_errors();
print_array($errors);
$lines = file('file.xml');
$output = fopen('errors.txt', 'w');
$distinctErrors = array();
foreach ($errors as $error)
{
if (!array_key_exists($error->line, $distinctErrors))
{
$distinctErrors[$error->line] = $error->message;
fwrite($output, "Error on line #{$error->line} {$lines[$error->line-1]}\n");
}
}
fclose($output);
?>
The print array is only to see the errors, its only optional.
Now my employer found a piece of code on the net
<?php
// test if the form has been submitted
if(isset($_POST['SubmitCheck'])) {
// The form has been submited
// Check the values!
$directory = $_POST['Path'];
if ( ! is_dir($directory)) {
exit('Invalid diretory path');
}
else
{
echo "The dir is: $directory". '<br />';
chdir($directory);
foreach (glob("*.xml") as $filename) {
echo $filename."<br />";
}
}
}
else {
// The form has not been posted
// Show the form
?>
<form id="Form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Path: <input type="text" name="Path"><br>
<input type="hidden" name="SubmitCheck" value="sent">
<input type="Submit" name="Form1_Submit" value="Path">
</form>
<?php
}
?>
That basically finds all xmls in a given directory and told me to combine the 2 scripts.
That i give the input directory, and the script should run on all xmls in that directory and give reports in txt files.
And i don't know how to do that, i'm a beginner in PHP took me about 2-3 days to write the simplest script. Can someone help me with this problem?
Thanks
Make a function aout of your code and replace all 'file.xml' to a parameter e.g. $filename.
In the second script where the "echo $filename" is located, call your function.

PHP File Delete Issue?

I have the following HTML form:
<form action='delete.php' method='POST'>
<table>
<div class = '.table'>
<?php
$dir = '../uploads/store/';
$newdir = ereg_replace('\.','',$dir);
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (!preg_match('/^(\.(htaccess|\.)?|index\.html)/',$file)) {
echo "<tr><td><font color = 'white'><a href='$newdir$file'>$file</a></font></td>";
echo "<td><input type='submit' value ='Delete'></td></tr>";
echo "<input align='right' type='hidden' value='$file' name='file'>";
}
}
closedir($dh);
}
}
?>
</div>
</table>
</form>
Which links to the following PHP script:
<?php
session_start();
$file = $_POST['file'];
$dir = '../uploads/store/';
$file = $dir . $file;
opendir($dir);
if(unlink($file)) {
echo "File sucessfully deleted";
$_SESSION['username'] = 'guitarman0831';
header('Refresh: 2;url=http://www.ohjustthatguy.com/uploads/uploads.html');
} else {
echo "Error: File could not be deleted";
$_SESSION['username'] = 'guitarman0831';
header('Refresh: 2;url=http://www.ohjustthatguy.com/uploads/uploads.html');
}
?>
However, when the Delete button is pressed in the HTML form, the item above the one intended to delete is deleted.
Hope this makes sense.
NOTE: I'm not going for security with these scripts, I'm going to work on that later. It's only me using this service right now.
Your HTML form needs to have the various submit buttons pass the value for $file instead of using hidden fields.
The problem is that all of the hidden fields are POSTed to delete.php when you submit the form. Then, since you haven't used the PHP-friendly HTML array variable syntax, PHP uses only the last of these to set the value of $_POST['file']. If you do a var_dump of $_POST in delete.php, you will see what the POSTed input is.
The easiest thing to do, with your current markup, is just to have each submit button be named file and pass $file as its value. i.e. you could do:
<button name="file" value="example.txt" type="submit">Delete</button>
Alternately, you could use radio buttons or some other markup.

Categories