<?php
class funWithMP3{
function play(){
global $play;
header("Content-Type: audio/x-mpegurl");
header("Content-Disposition: filename=\"playlist.m3u\"");
echo $this->linkencode("http://".$_SERVER[HTTP_HOST]."/".$play);
// The line above will need to be modified for example
// if you run from a directory named 'mp3' change like so:
// echo $this->linkencode("http://".$_SERVER[HTTP_HOST]."/mp3/".$play);
}
// The following function 'linkencode' by
// dphantom@ticino.com
// 03-Feb-2002 03:48
// found at php.net
function linkencode($p_url){
$ta = parse_url($p_url);
if (!empty($ta[scheme])) { $ta[scheme].='://'; }
if (!empty($ta[pass]) and !empty($ta[user])) {
$ta[user].=':';
$ta[pass]=rawurlencode($ta[pass]).'@';
}elseif(!empty($ta[user])) {
$ta[user].='@';
}
if (!empty($ta[port]) and !empty($ta[host])) {
$ta[host]=''.$ta[host].':';
} elseif (!empty($ta[host])) {
$ta[host]=$ta[host];
}
if (!empty($ta[path])) {
$tu='';
$tok=strtok($ta[path], "\\/");
while (strlen($tok)) {
$tu.=rawurlencode($tok).'/';
$tok=strtok("\\/");
}
$ta[path]='/'.trim($tu, '/');
}
if (!empty($ta[query])) { $ta[query]='?'.$ta[query]; }
if (!empty($ta[fragment])) { $ta[fragment]='#'.$ta[fragment]; }
return implode('', array($ta[scheme], $ta[user], $ta[pass], $ta[host], $ta[port], $ta[path], $ta[query], $ta[fragment]));
}
/*ShowList*/
function showlist(){
global $PHP_SELF;
$mydirectory=opendir(".");
while($name=readdir($mydirectory)){
list ($myfilename, $myfilenameext) = split ("\.", $name);
if (strtolower($myfilenameext)=="mp3"){
echo "<a href=\"$PHP_SELF?play=$name\">$name</a><br>\n";
}
}
closedir($mydirectory);
}
function main(){
global $play;
switch (true) {
case (isset($play)) : $this->play(); return;
default : $this->showlist(); return;
}
}
}
?>
|