Skip to content Skip to sidebar Skip to footer

Embed Randomly Named Mp3

Here's my code: I would like the src for the .mp3 to take in t

Solution 1:

This should do it:

$files = glob("/path/to/directory/*.mp3");
$random = array_rand($files)

Then do this:

<embedsrc="<?phpecho$random?>"width="140"height="40"autostart="true"loop="TRUE"></embed>

Solution 2:

Try This: It will Work, I used original code found in answers and did some tweaking by adding array($files) in the $random = array_rand(); variable statement

You will first need to put the PHP code in the body like this

<?php$files = glob("assets/songs/SayYesToLove/*.mp3");
$random = array_rand(array($files));
?>

next add this just outside that php code in the body

<embedsrc="<?phpecho$files[$random]; ?>"width="140"height="40"autostart="true"loop="TRUE"></embed>

Please Notice the echo output in the src file. This will ensure it gets outputted to your page. Also don't forget to use the ; at the end of every php variable statement as this can through some errors.

Post a Comment for "Embed Randomly Named Mp3"