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
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.
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
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
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
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
Can someone please just give me the script with examples in it, Which i can change to my own please, Thankyou
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
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.
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):