-
Notifications
You must be signed in to change notification settings - Fork 2
/
getwav.php
53 lines (42 loc) · 1.54 KB
/
getwav.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
<?php
require_once('config.inc.php');
// Open MySQL connection
$db = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($db->connect_errno) {
echo "Failed to connect to MySQL: (" . $db->connect_errno . ") " . $db->connect_error;
}
$callid = $_GET['id'];
if (!$callid) {
die("No call ID specified!");
}
$sql = "SELECT cdr.id, cdr_next.fbasename, cdr.calldate, cdr.caller, cdr.called FROM `cdr` LEFT JOIN cdr_next ON cdr.id = cdr_next.cdr_ID WHERE cdr.id = $callid";
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
$row = $result->fetch_assoc();
$calldatelong = $row['calldate'];
$calltime = strtotime($calldatelong);
$callday = date('Y-m-d', $calltime);
$calltimestamp = date('YmdHis', $calltime);
$caller = $row['caller'];
$called = $row['called'];
$wavfile = $wav_path . "{$callday}/" . $row['fbasename'] . '.wav';
$outfilename = "{$calltimestamp}-{$caller}-to-{$called}.wav";
//echo "$calldatelong $calltime $callday $calltimestamp $caller $called $wavfile $outfilename";
if (file_exists($wavfile)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$outfilename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($wavfile));
ob_clean();
flush();
readfile($wavfile);
exit;
} else {
die("File {$wavfile} does not exist.");
}
?>