forked from m-dark/sip-phone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdr_audio.php
81 lines (77 loc) · 2.09 KB
/
cdr_audio.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
f (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
/**
* @file
* plays recording file
*/
if (isset($_REQUEST['cdr_file'])) {
include_once("crypt.php");
$REC_CRYPT_PASSWORD = (isset($amp_conf['AMPPLAYKEY']) && trim($amp_conf['AMPPLAYKEY']) != "")?trim($amp_conf['AMPPLAYKEY']):'TheWindCriesMary';
$crypt = new Crypt();
$opath = $_REQUEST['cdr_file'];
$path = $crypt->decrypt($opath,$REC_CRYPT_PASSWORD);
// Gather relevent info about file
$size = filesize($path);
$name = basename($path);
$extension = strtolower(substr(strrchr($name,"."),1));
// This will set the Content-Type to the appropriate setting for the file
$ctype ='';
switch( $extension ) {
case "WAV":
$ctype="audio/x-wav";
break;
case "wav":
$ctype="audio/x-wav";
break;
#---------------------
case "mp3":
$ctype="audio/mpeg";
break;
#---------------------
case "ulaw":
$ctype="audio/basic";
break;
case "alaw":
$ctype="audio/x-alaw-basic";
break;
case "sln":
$ctype="audio/x-wav";
break;
case "gsm":
$ctype="audio/x-gsm";
break;
case "g729":
$ctype="audio/x-g729";
break;
default: //not downloadable
// echo ("<b>404 File not found! foo</b>");
// TODO: what to do if none of the above work?
break ;
}
$fp=fopen($path, "rb");
if ($size && $ctype && $fp) {
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: audio file");
header("Content-Type: " . $ctype);
header("Content-Disposition: attachment; filename=" . $name);
header("Content-Transfer-Encoding: binary");
#---------------------
header("Accept-Ranges: bytes");
header("Connection: close");
header("Content-Length: $size");
header("Content-Range:bytes 0-$size/$size");
header("Content-length: " . $size);
#---------------------
$chunksize = 1*(1024*1024);
while (!feof($fp)) {
$buffer = fread($fp, $chunksize);
echo $buffer;
ob_flush();
flush();
}
fclose($fp);
}
}
?>