1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Directory include (MP3)

Discussion in 'PHP' started by webber09, Jan 14, 2011.

  1. #1
    Hi again all,

    Is there a way I can have a form generated by PHP a list all the songs I have on my server... e.g someone comes onto my site looks through the music list, selects the track they want then it plays it.

    Basically because i am going to be uploading A LOT of files i dont want to have to list them all in the html or xml file. so i need the PHP to read the file name and creat a link to it or load it into a player.

    Thanks :D
     
    webber09, Jan 14, 2011 IP
  2. ssmm987

    ssmm987 Member

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    3
    Trophy Points:
    43
    #2
    ssmm987, Jan 14, 2011 IP
  3. webalani

    webalani Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you can follow that way;
    1-Read dir
    2-divide names (pop/john/1.mp3 => string1="pop", string2="john", string3="1.mp3") you can do it using explode function
    3-then, you can categorise them, or you can what you wabt. if you want to link to mp3 directly, you can do it using code like;
    echo '<a href="http://www.xxxxx.com/'.$string1.'/'.$string2.'/'.$string3'">$string3</a>';
     
    webalani, Jan 14, 2011 IP
  4. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #4
    ah okay... thanks webalani :D
     
    webber09, Jan 20, 2011 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    <?php
    
    foreach(glob('*.mp3') as $file) {
    echo $file."<br />\r\n";
    }
    PHP:
    That should get you started, for more info refer to the glob() php.net documentation page.
     
    danx10, Jan 21, 2011 IP
  6. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #6
    
    $f = opendir("mp3");
    
    while($mp3 =  readdir($f))
    {
     if ($mp3 != "." && $mp3 != "..")
     {
      echo "<a href='mp3/".$mp3."'>$mp3</a>";
     }
    }
    
    PHP:
    hope that helps
     
    G3n3s!s, Jan 22, 2011 IP
  7. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #7
    that works fantastic thanks! is it posiable that when you click on it, it will load into a new page with a proper player - OR - if i can have the list and player on one page and it will just 'load' load it into the player? also is it possable to 'filter' out the .mp3 part?
     
    webber09, Jan 22, 2011 IP
  8. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #8
    filter out?

    umm, about that loader, yes it's possible but you should ... umm, I think it's client side or you have to done it via changing some php informations so you will have to call php ... I will look for something, wait
     
    G3n3s!s, Jan 22, 2011 IP
  9. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #9
    umm.

    $f = opendir("mp3");
    
    while($mp3 =  readdir($f))
    {
     if ($mp3 != "." && $mp3 != "..")
     {
      echo "<a href='mp3.php?file=".$mp3."'>$mp3</a>";
     }
    }
    PHP:
    now create new php file mp3.php and put there this

    
    <?php
    echo '<body marginwidth="0" marginheight="0"><embed width="100%" height="100%" name="plugin" src="mp3/'.$_GET['file'].'" type="audio/mpeg"></body>';
    PHP:
     
    G3n3s!s, Jan 22, 2011 IP
  10. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #10
    am i able to put that code it work in here somehow?

    <OBJECT id='mediaPlayer1' width="180" height="50" 
    classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' 
    codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'
    standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>
    <param name='fileName' value="Stream URL or Full File Path Goes Here">
    <param name='animationatStart' value='true'>
    <param name='transparentatStart' value='true'>
    <param name='autoStart' value="false">
    <param name='showControls' value="true">
    <param name ="ShowAudioControls"value="true"> 
    <param name="ShowStatusBar" value="true">
    <param name='loop' value="false">
    <EMBED type='application/x-mplayer2'
    pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'
    id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='-1' 
    bgcolor='darkblue' showcontrols="true" showtracker='-1' 
    showdisplay='0' showstatusbar='-1' videoborder3d='-1' width="420" height="380"
    src="Stream URL or Full File Path Goes Here" autostart="true" designtimesp='5311' loop="false">
    </EMBED>
    </OBJECT>
    HTML:
     
    webber09, Jan 22, 2011 IP
  11. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #11
    <OBJECT id='mediaPlayer1' width="180" height="50"
    classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'
    codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'
    standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>
    <param name='fileName' value="mp3/<?php echo $_GET['file']; ?>">
    <param name='animationatStart' value='true'>
    <param name='transparentatStart' value='true'>
    <param name='autoStart' value="false">
    <param name='showControls' value="true">
    <param name ="ShowAudioControls"value="true">
    <param name="ShowStatusBar" value="true">
    <param name='loop' value="false">
    <EMBED type='application/x-mplayer2'
    pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'
    id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='-1'
    bgcolor='darkblue' showcontrols="true" showtracker='-1'
    showdisplay='0' showstatusbar='-1' videoborder3d='-1' width="420" height="380"
    src="mp3/<?php echo $_GET['file']; ?>" autostart="true" designtimesp='5311' loop="false">
    </EMBED>
    </OBJECT>
    PHP:
     
    G3n3s!s, Jan 22, 2011 IP
  12. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #12
    i always forget the dam echo's!! i tried to do that but left them out, evidently wouldn't work. i know it needs them just dam forget
     
    webber09, Jan 22, 2011 IP
  13. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #13
    if it don't work for you now (this code I gave you), sorry I forgot one "/" so put it again and it will work ... (edited it)

    Don't worry, I was forgoting ";" when I was starting with php ;)
     
    G3n3s!s, Jan 22, 2011 IP
  14. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #14
    and another problem rises!! it is now putting in ./mp3s/Nelly , rather than ./mp3s/Nelly & Keri Hilson - Liv Tonight.mp3 :(
     
    webber09, Jan 22, 2011 IP
  15. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #15
    hmm

    if you see list of these mp3's, do you see link to

    mp3.php?file=Nelly & Keri Hilson.mp3
    or

    mp3.php?file=Nelly

    ?
     
    G3n3s!s, Jan 22, 2011 IP
  16. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #16
    the link shows correct, its just when it gets added to the src or value in the player
     
    webber09, Jan 22, 2011 IP
  17. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #17
    webber09, Jan 22, 2011 IP
  18. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #18
    yep, I think Microshit can't handle that.

    try this code, don't worry about browser, it will work
    <oBJECT> 
    <EMBED. 
    width="420" height="380" 
    src="mp3/'.$_GET["file"].'" autostart="true" designtimesp="5311" loop="false"> 
    </EMBED> 
    </OBJECT>
    PHP:
     
    G3n3s!s, Jan 22, 2011 IP
  19. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #19
    I see main problem has character "&". If you delete it it will be great
     
    G3n3s!s, Jan 22, 2011 IP
  20. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #20
    mate trust me if i had my way i would be on mac or linux!! My laptop will not let me change to any other OS for some strainge reason! and sadly cannot afford a mac right now.

    anyway as you may be able to see, NO PLAYER AGAIN! chrome and firefox will not read the code!
     
    webber09, Jan 22, 2011 IP