我们有一个VOIP服务器,用于存储用于呼叫录音的wav文件。我的目的是整理一个PHP文件,我可以在文件的URL中传递calldate和uniqueid值(因为服务器将这些作为文件名的一部分存储)以检索文件的链接。
但是,尝试这样做时会出现以下错误:
“解析错误:语法错误,第42行的/var/www/html/maint/helloworld.php意外$结束”
<?php
function getRecordingLink($callDate, $uniqueId){
$callDate_arr = explode(' ', $callDate);
$removeChar = array('-',':');
foreach($callDate_arr as $value){
$callDate_arr_adj[] = str_replace($removeChar,'',$value);
}
$audioDirectory_array = array();
if ($handle = opendir('/var/spool/asterisk/monitor/')) {
while (false != ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$audioDirectory_array[] = $file;
}
}
closedir($handle);
}
foreach($audioDirectory_array as $key => $value){
if (preg_match ("/".$uniqueId."/i", $value)) {
if(file_exists('/var/spool/asterisk/monitor/'.$value)){
$wavFile = $value;
//return '<a href="/maint/modules/cdrreport/monitor/'.$wavFile.'" target="_blank">Recorded File</a>';
return '/maint/cache/monitor/' . $wavFile;
}
}else{
//return "Not Recorded";
}
getRecordingLink ('20110513','1305274000.2'); //sample calldate and uniqueid values for testing
&GT?;
以下是MySQL表的描述,我将从中获取值以传递给此calidate和uniqueid`的URL
mysql> describe cdr
-> ;
+-------------+--------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------------------+-------+
| calldate | datetime | NO | | 0000-00-00 00:00:00 | |
| clid | varchar(80) | NO | | | |
| src | varchar(80) | NO | | | |
| dst | varchar(80) | NO | | | |
| dcontext | varchar(80) | NO | | | |
| channel | varchar(80) | NO | | | |
| dstchannel | varchar(80) | NO | | | |
| lastapp | varchar(80) | NO | | | |
| lastdata | varchar(80) | NO | | | |
| duration | int(11) | NO | | 0 | |
| billsec | int(11) | NO | | 0 | |
| disposition | varchar(45) | NO | | | |
| amaflags | int(11) | NO | | 0 | |
| accountcode | varchar(20) | NO | | | |
| uniqueid | varchar(32) | NO | | | |
| userfield | varchar(255) | NO | | | |
+-------------+--------------+------+-----+---------------------+-------+
答案 0 :(得分:1)
是的,还有另外一个很难看的:-p
您在getRecordingLink()
上方文件底部缺少两个大括号:
function getRecordingLink($callDate, $uniqueId){
$callDate_arr = explode(' ', $callDate);
$removeChar = array('-',':');
foreach($callDate_arr as $value){
$callDate_arr_adj[] = str_replace($removeChar,'',$value);
}
$audioDirectory_array = array();
if ($handle = opendir('/var/spool/asterisk/monitor/')) {
while (false != ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$audioDirectory_array[] = $file;
}
}
closedir($handle);
}
foreach($audioDirectory_array as $key => $value){
if (preg_match ("/".$uniqueId."/i", $value)) {
if(file_exists('/var/spool/asterisk/monitor/'.$value)){
$wavFile = $value;
//return '<a href="/maint/modules/cdrreport/monitor/'.$wavFile.'" target="_blank">Recorded File</a>';
return '/maint/cache/monitor/' . $wavFile;
}
}else{
//return "Not Recorded";
}
}
}
getRecordingLink ('20110513','1305274000.2');
我从here得到的错误是:
解析错误:语法错误,意外结束/homepages/26/d94605010/htdocs/lz/writecodeonline.com/php/index.php(98):第32行的eval()代码
该文件现在为我解析,但我无法测试它实际上做了什么。如果这不起作用,请在评论中遵循我的建议。