Very Hard Question !

Discussion in 'HTML & Website Design' started by geekazoid, Jul 2, 2006.

  1. #1
    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 ?
     
    geekazoid, Jul 2, 2006 IP
  2. sandossu

    sandossu Guest

    Messages:
    2,274
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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
     
    sandossu, Jul 2, 2006 IP
  3. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Please could you help me with the script, Im affraid im not to clever with it
     
    geekazoid, Jul 2, 2006 IP
  4. Albert_chu

    Albert_chu Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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..
     
    Albert_chu, Jul 4, 2006 IP
  5. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ok does anyone know this script ? thanx peeps
     
    geekazoid, Jul 4, 2006 IP
  6. brian394

    brian394 Well-Known Member

    Messages:
    226
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    108
    #6
    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):
     
    brian394, Jul 5, 2006 IP
  7. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ok but which folder do i put all my songs in and do i have to rename them anything ?
     
    geekazoid, Jul 6, 2006 IP
  8. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    ok i know what to do with the folder but what do i rename them ?
     
    geekazoid, Jul 6, 2006 IP
  9. mixke

    mixke Prominent Member

    Messages:
    5,917
    Likes Received:
    590
    Best Answers:
    0
    Trophy Points:
    310
    #9
    if you are talking about renaming the songs ( and following the idea suggested by sandossu ) then renaming will surely help.
    Peace..!!
     
    mixke, Jul 6, 2006 IP
  10. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    to what ?

    1.mp3
    2.mp3
    3.mp3 ?????? Like that ?????
     
    geekazoid, Jul 6, 2006 IP
  11. mixke

    mixke Prominent Member

    Messages:
    5,917
    Likes Received:
    590
    Best Answers:
    0
    Trophy Points:
    310
    #11
    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..!!
     
    mixke, Jul 6, 2006 IP
    educities likes this.
  12. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    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
     
    geekazoid, Jul 6, 2006 IP
  13. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    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
     
    geekazoid, Jul 6, 2006 IP
  14. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    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
     
    geekazoid, Jul 6, 2006 IP
  15. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    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
     
    geekazoid, Jul 6, 2006 IP