So i have this media player which links to a file in my server called Song.mp3 I have this media player running as my song of the day, I have to rename and upload a new song everyday. What a want is a way to put about 200 songs in a folder and let the player rotate through them each day. One Per Day ! Any Wizzkids Know how to do this ?
I have an idea. You put the 200 songs named 1.mp3, 2.mp3 ... 200.mp3 Using php, you make a script that gets them in order, 1,2 ,3 ... 200 and renames them to song-of-the-day.mp3 daily, one each day. You set the player to play song-of-the-day.mp3 and you are done. If you have trouble with the script i can help Good Luck
im pretty sure you dont really have to rename them into ascending numbers..it wouldnt really make a difference if u used the real name or not..
Try this... Place this snippet of PHP code at the top of your page: <?php // Put the location of the folder here with all your songs (mp3s) // Note: Remember to prefix the folder name with a dot (.) and a forward slash (/) $folder_location = "./songs"; // ---------------------------------------------------------------- // You shouldn't have to edit beyond this point // ---------------------------------------------------------------- $dir_handle = opendir($folder_location); while (false !== ($file = readdir($dir_handle))) { if (($file != '.') && ($file != '..')) { $filenames[] = $file; // add it's filename to an array } } closedir($dir_handle); if (isset($filenames) == true) { //Create a number which is the size of the array plus the number of days in the current year... $num = count($filenames) + date("z"); //Next, mod that number by the number of items in your array to find the right index... $num = $num % count($filenames); } ?> Code (markup): Next, scroll down in your HTML file to the place where you originally put "Song.mp3" and replace the filename "Song.mp3" with this... <?php echo $filenames[$num]; ?> Code (markup):
if you are talking about renaming the songs ( and following the idea suggested by sandossu ) then renaming will surely help. Peace..!!
yeps..according to the above renaming them to 1/2/3/4........../200.mp3 will be okiez if he is helping with the script. it wont be taking much time to rename them ..so make a backup on ur own hdd and rename.If anything goes wrong like if you dont get the script then you will be having the backup with you. Peace..!!
ok i have pasted the code and uploaded the folder and the songs and the page which is below ... The music player (top right) doesnt seem to be able to find the mp3s http://www.geekazoid.co.uk/Index.php
OH OH OH OH OH OH !!! This is brilliant its working !!!!! Brian you legend thats class ! !!! Only thing is i need to put the mp3s in the folder and in my htdocs folder which is where the file is It seems like it uses the folder to count the files and then it uses the main folder ( the htdocs folder ) to supply the mp3 file ?? is there anyway of getting the mp3 file from the /songs folder
OH OH OH OH OH OH OH OH OH I FIXED IT I just shoved /songs in front of <?php echo $filenames[$num]; ?> Brilliant thankyou soooo much brian. This Thread Is Finished ! Its working Exactly as i wanted brilliant ! Ta
ok one last question say i wanted to use that script to show images in a folder which would rotate per day, and i wanted to have that on the same page as the Song one. In which way would i have to alter the script for the image one