Rotating Random Item Each Day

Discussion in 'HTML & Website Design' started by geekazoid, Jun 25, 2006.

  1. #1
    I have this script which lets me place one line of script onto my page and that links to a folder which i have on my server which is full of .html files which all contain one picture. Which lets my page have a random picture displayed on it each page load.

    I would now like to make a "picture of the day" But i do not have the time to be uploading a new picture every day so i was wondering is there a script which i can paste into my page which links to a folder which contains html files which will randomly change each day ?

    Thanx In Advance For Any Replies :)
     
    geekazoid, Jun 25, 2006 IP
  2. DXL

    DXL Peon

    Messages:
    380
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    In PHP:

    
    <?php
    function getPotD($dir) {
        $array = split(' ', shell_exec('ls -A '.$dir));
        return $array[(date('dd')+0) % count($array)];
    }
    ?>
    
    PHP:
    To use it:
    
    <?php print '<img src="'.getPotD('certaindir/').'" alt="Picture of the Day" />'; ?>
    
    PHP:
    Yet untested.
     
    DXL, Jun 25, 2006 IP
  3. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #3
    You can use ASP also, or you can spend a bit of time and write it with Java Script if you can't use PHP or ASP
     
    ludwig, Jun 25, 2006 IP
  4. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanx Guys So Far, Does anyone though have any tested working scripts
     
    geekazoid, Jun 25, 2006 IP
  5. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #5
    there is the PHP script up up above.

    I don't think you can find a ready made script, you'll need to write it yourself or ask someone to do it for you
     
    ludwig, Jun 26, 2006 IP
  6. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Ok, Could some one write the script for me please :D
     
    geekazoid, Jun 26, 2006 IP
  7. DXL

    DXL Peon

    Messages:
    380
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #7
    That is it. And testing won't hurt you. I hope.
     
    DXL, Jun 26, 2006 IP
  8. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ok thanx for the script. I would go and test it if i knew what to do.

    Could someone explain what i need to do with the script and please please please could someone explain the differant things i must change and give examples. thanx
     
    geekazoid, Jun 27, 2006 IP
  9. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #9
    I think you need some tutorials and not our help

    find some online tutorial on either ASP or PHP and start learning, if you need to know all the procedure you need to study something. It takes time to explain all that and the tutorials will do really good for you
     
    ludwig, Jun 27, 2006 IP
  10. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Can someone please just give me the script with examples in it, Which i can change to my own please, Thankyou
     
    geekazoid, Jun 27, 2006 IP
  11. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #11
    I, for one, find that I do not care to help someone who is not willing to do for himself. If all you want is the stuff handed to you without effort on your part, hire it done.

    gary
     
    kk5st, Jun 27, 2006 IP
  12. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I dont know what i have to do ? !! How can i do it for myself ?
     
    geekazoid, Jun 27, 2006 IP
  13. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Ok i have spent hours on this now and its just getting worse. I dont know what bits i have to change and what bits i dont change, I have tried reading php tutorials but nothing really like this comes up. Please someone help me. :(
     
    geekazoid, Jun 27, 2006 IP
  14. brian394

    brian394 Well-Known Member

    Messages:
    226
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    108
    #14
    Try this...

    
    <?php
    
    // Put the location of the folder here with all your .html files
    // Note: Remember to prefix the folder name with a dot (.) and a forward slash (/)
    $folder_location = "./images";
    
    // ----------------------------------------------------------------
    // You shouldn't have to edit beyond this point
    // ----------------------------------------------------------------
    $dir_handle = opendir($folder_location);
    while (false !== ($file = readdir($dir_handle))) {
     if (strpos($file, '.html') > 0) { // only look at .html files
      $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);
    
     //Set the base href
     echo '<base href="' . $folder_location . '/" />';
    
     //Grab the file
     include($folder_location . "/" . $filenames[$num]);
    
     //Reset the base href
     echo '<base href="./" />';
    }
    
    ?>
    
    Code (markup):
     
    brian394, Jul 1, 2006 IP