I always wanted someone to enter a page to play some random random ale in a folder.
I tried to use this
<?php
$dir_path = "data/";
$extensions_array = array('mp3');
if(is_dir($dir_path))
{
$files = scandir($dir_path);
for($i = 0; $i < count($files); $i++)
{
if($files[$i] !='.' && $files[$i] !='..')
{
$file = pathinfo($files[$i]);
$extension = $file['extension'];
if(in_array($extension, $extensions_array))
{
echo "<audio loop='loop' autoplay='autoplay'>
<source src='$dir_path$files[$i]'>
</audio> ";
}
}
}
}
?>
But on the page it loads all audios at once. Can someone help me?
When I look at the source code, all the audio files that are in the folder appear.
<audio loop='loop' autoplay='autoplay'> <source src='data/defacee.mp3'></audio>
<audio loop='loop' autoplay='autoplay'> <source src='data/sound.mp3'> </audio>