dongmeng4742 2011-06-08 14:03
浏览 74
已采纳

获取PHP中的文件链接

We have a VOIP server that stores wav files for call recordings. My intention was to put together a PHP file, where i can pass the calldate and uniqueid value in the URL for the file (since the server stores these as part of the filename) to retrieve a link to the file.

However, i get the following error when trying to do so:

"Parse error: syntax error, unexpected $end in /var/www/html/maint/helloworld.php on line 42"

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

?>

Here is the description of the MySQL table from where i will be picking up values to pass to this URL for calldate and uniqueid`

    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   |     |                     |       |
+-------------+--------------+------+-----+---------------------+-------+
  • 写回答

1条回答 默认 最新

  • doudan4834 2011-06-08 14:24
    关注

    Right, just had another good hard look at this :-p

    You are missing two curly braces from the bottom of the file above 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'); 
    

    The error I got from here was:

    Parse error: syntax error, unexpected $end in /homepages/26/d94605010/htdocs/lz/writecodeonline.com/php/index.php(98): eval()'d code on line 32

    The file parses for me now, but I can't test what it actually does. If this doesn't work, please follow my advice in the comments.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路