Loans - Credit Counseling - Debt Help - Mobile Phones - Myspace Codes

PDA

View Full Version : Rotating Random Item Each Day


geekazoid
Jun 25th 2006, 4:18 am
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 :)

DXL
Jun 25th 2006, 9:56 am
In PHP:


<?php
function getPotD($dir) {
$array = split(' ', shell_exec('ls -A '.$dir));
return $array[(date('dd')+0) % count($array)];
}
?>


To use it:

<?php print '<img src="'.getPotD('certaindir/').'" alt="Picture of the Day" />'; ?>


Yet untested.

ludwig
Jun 25th 2006, 12:06 pm
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

geekazoid
Jun 25th 2006, 1:05 pm
Thanx Guys So Far, Does anyone though have any tested working scripts

ludwig
Jun 26th 2006, 3:31 am
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

geekazoid
Jun 26th 2006, 11:26 am
Ok, Could some one write the script for me please :D

DXL
Jun 26th 2006, 12:57 pm
That is it. And testing won't hurt you. I hope.

geekazoid
Jun 27th 2006, 1:56 am
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

ludwig
Jun 27th 2006, 4:41 am
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

geekazoid
Jun 27th 2006, 11:27 am
Can someone please just give me the script with examples in it, Which i can change to my own please, Thankyou

kk5st
Jun 27th 2006, 2:09 pm
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

geekazoid
Jun 27th 2006, 2:19 pm
I dont know what i have to do ? !! How can i do it for myself ?

geekazoid
Jun 27th 2006, 2:43 pm
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. :(

brian394
Jul 1st 2006, 5:58 am
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="./" />';
}

?>