php/html5播放列表使用glob()


php/html5 playlist using glob()

我正在使用php glob()获取歌曲文件夹中的所有歌曲然后使用array_rand来获得一首随机歌曲,然后使用foreach循环来循环歌曲。不管怎样,我都可以让工作

    <!DOC TYPE HTML>
    <html>
    <head>
    <title>ymp</title>
    <link rel="stylesheet" href="style.css" type="text/css" />
    </head>
     <body>
     <h1>YMP RADIO</h1>
     <?php require ("dropmenu.html"); ?>


      <?php     
        $music = glob("songs/*");  // get all files in the music directory
        shuffle($music);
        foreach ($music as $song){           // try and loop a random songs
        }
         var_dump($song)
       ?>
         <audio id="player" src="<?php  $song ?>" type="audio/mpeg"></audio>
         <audio id="player" src="<?php  $song ?>" type="audio/ogg"></audio>
       <br /><br /><br />
        <div> 
        <table border="1px" >
        <tr>
        <td class="tdpage" >
        <img src="ymplogo5.jpg" alt=""  />
        <p><button  class="botton";   onclick="document.getElementById('player').play()">Play</button>
       <button     class="botton";   onclick="document.getElementById('player').pause()">Pause</button>
         <button     class="botton";   onclick="document.getElementById('player').volume+=0.1">Volume up </button>
          <button     class="botton";          onclick="document.getElementById('player').volume-=0.1">Volume down</button>
     </td>
     </tr>
     </table>   
     </div> 
     <br /><br /><br />
     </body>
     </html>

我相信你想以随机顺序循环它们,在这种情况下使用shuffle()

$music = glob("songs/");  // get all files in the music directory
shuffle($music);
      foreach ($music as $song){           
//code
       }

您当前的glob模式只是匹配一个目录。

要使匹配目录中的所有文件,请使用通配符"*"。

$music=glob("songs/*");