Array to Provide One Random MP3 to Audio Tag
Can you guys please tell me why the PHP code below fails to provide an MP3 file to the audio tag?
There are seven mp3 files in the folder "bgAudio" that is in the root directory.
Code:
<?php
$files = glob('/bgAudio/*.mp3'); // get all seven .mp3 files in bgAudio directory - 1.mp3, 2.mp3, 3.mp3, 4.mp3, 5.mp3, 6.mp3, and 7.mp3
$fname = $files[array_rand($files)]; // get a random filename
echo $fname;
?>
<audio autoplay="autoplay" id="bgAudio">
<source src="<?php echo $fname; ?>"/>
</audio>
<script>
jQuery(function($) {
$("#bgAudio").prop('volume', .7);
window.setVolume = function(bgAudio,vol) {
sounds[bgAudio].volume = .7;
}
});
</script>