PHP Classes

File: funWithMP3.inc.php

Recommend this page to a friend!
  Classes of Pierre Marceau   funWithMP3   funWithMP3.inc.php   Download  
File: funWithMP3.inc.php
Role: Class source
Content type: text/plain
Description: The class
Class: funWithMP3
Access your MP3's
Author: By
Last change: sdfsd
Date: 21 years ago
Size: 1,986 bytes
 

Contents

Class file image Download
<?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;
  }
}
}
?>