-
Notifications
You must be signed in to change notification settings - Fork 0
/
mp3.php
85 lines (78 loc) · 2.19 KB
/
mp3.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
82
83
84
85
<?php
class mp3{
var $str;
var $time;
var $frames;
// Create a new mp3
function mp3($path="")
{
if($path!="")
{
$this->str = file_get_contents($path);
}
}
// Put an mp3 behind the first mp3
function mergeBehind($mp3){
$this->str .= $mp3->str;
}
// Calculate where's the end of the sound file
function getIdvEnd(){
$strlen = strlen($this->str);
$str = substr($this->str,($strlen-128));
$str1 = substr($str,0,3);
if(strtolower($str1) == strtolower('TAG')){
return $str;
}else{
return false;
}
}
// Calculate where's the beginning of the sound file
function getStart(){
$strlen = strlen($this->str);
for($i=0;$i<$strlen;$i++){
$v = substr($this->str,$i,1);
$value = ord($v);
if($value == 255){
return $i;
}
}
}
// Remove the ID3 tags
function striptags(){
//Remove start stuff...
$newStr = '';
$s = $start = $this->getStart();
if($s===false){
return false;
}else{
$this->str = substr($this->str,$start);
}
//Remove end tag stuff
$end = $this->getIdvEnd();
if($end!==false){
$this->str = substr($this->str,0,(strlen($this->str)-129));
}
}
// Display an error
function error($msg){
//Fatal error
die('<strong>audio file error: </strong>'.$msg);
}
// Send the new mp3 to the browser
function output($path){
//Output mp3
//Send to standard output
if(ob_get_contents())
$this->error('Some data has already been output, can\'t send mp3 file');
if(php_sapi_name()!='cli'){
//We send to a browser
header('Content-Type: audio/mpeg3');
if(headers_sent())
$this->error('Some data has already been output to browser, can\'t send mp3 file');
header('Content-Length: '.strlen($this->str));
header('Content-Disposition: attachment; filename="'.$path.'"');
}
echo $this->str;
return '';
}
}