bobgo2728 Posted February 28, 2008 Report Share Posted February 28, 2008 OK I found this script that will do a image of the day. It changes over at midnight of the server time. Which is fine with me. Now I am wondering how I can have it 1) display the images in a calander view below so that way there are thumbnails. 2) how to have it be able to load up more then 31 images so I don't have to change it for several months down the road. Anyway here is the code.<?php$totalPics="31"; $photoOfTheDay = Array ( '1' => 'files/photo1.jpg' , '2' => 'files/photo2.jpg' , '3' => 'files/photo3.jpg' , '4' => 'files/photo4.jpg' , '5' => 'files/photo5.jpg' , '6' => 'files/photo6.jpg' , '7' => 'files/photo7.jpg' , '8' => 'files/photo8.jpg' , '9' => 'files/photo9.jpg' , '10' => 'files/photo10.jpg' , '11' => 'files/photo11.jpg' , '12' => 'files/photo12.jpg' , '13' => 'files/photo13.jpg' , '14' => 'files/photo14.jpg' , '15' => 'files/photo15.jpg' , '16' => 'files/photo16.jpg' , '17' => 'files/photo17.jpg' , '18' => 'files/photo18.jpg' , '19' => 'files/photo19.jpg' , '20' => 'files/photo20.jpg' , '21' => 'files/photo21.jpg' , '22' => 'files/photo22.jpg' , '23' => 'files/photo23.jpg' , '24' => 'files/photo24.jpg' , '25' => 'files/photo25.jpg' , '26' => 'files/photo26.jpg' , '27' => 'files/photo27.jpg' , '28' => 'files/photo28.jpg' , '29' => 'files/photo29.jpg' , '30' => 'files/photo30.jpg' , '31' => 'files/photo31.jpg' ,);// Place day of month in variable 'x'//$x=date("d"); // A website vistor made a suggestion to change the date function to use j // instead of d. This causes the date to be read without leading zeros.$x=date("j");// If value of date exceeds the amount of photos then pick a random photo to displayif($x > $totalPics) { $x=rand(1,$totalPics); }// Display imageecho <<<EOC<center><img src="$photoOfTheDay[$x]"></center>EOC;?> Quote Link to post Share on other sites
jsbowen Posted February 28, 2008 Report Share Posted February 28, 2008 (edited) 1) This is the part of the code that displays the image:// Display imageecho <<<EOC<center><img src="$photoOfTheDay[$x]"></center>EOC;This is really the only necessary part:<img src="$photoOfTheDay[$x]">2) Change the number listed here:$totalPics="31";Then just add a new entry to the bottom of the array with the next number in the sequence.'31' => 'files/photo31.jpg' ,'32' => 'files/photo32.jpg' , Edited February 28, 2008 by jsbowen Quote Link to post Share on other sites
jcl Posted February 29, 2008 Report Share Posted February 29, 2008 (edited) The array is unnecessary.$totalPics = 30;function photoOfTheDay($n){ global $totalPics; $n = $n > $totalPics ? rand(1, $totalPics) : $n; return 'files/photo' . strval($n) . '.jpg';}You could span several months by having separate directories for each month, passing the month number into the function, and returning "files/photo/$month/$day.jpg". Or one directory with "photo$month$day.jpg". Or by using the day of the year (date('z')). Or by using "$month * 31 + $day;". Or.... Edited February 29, 2008 by jcl Quote Link to post Share on other sites
bobgo2728 Posted March 1, 2008 Author Report Share Posted March 1, 2008 OK give me an example of what the code would look like. I would like to have this thing be abled to be loaded up for several months down the road.The array is unnecessary.$totalPics = 30;function photoOfTheDay($n){ global $totalPics; $n = $n > $totalPics ? rand(1, $totalPics) : $n; return 'files/photo' . strval($n) . '.jpg';}You could span several months by having separate directories for each month, passing the month number into the function, and returning "files/photo/$month/$day.jpg". Or one directory with "photo$month$day.jpg". Or by using the day of the year (date('z')). Or by using "$month * 31 + $day;". Or.... Quote Link to post Share on other sites
jcl Posted March 3, 2008 Report Share Posted March 3, 2008 (edited) The code for the day-of-the-year version would identical to the code post except that the range of the $n parameter would be [0,365] instead of [1,31].The code for the day-of-the-month would be something likefunction photoOfTheDay($month, $day){ return 'files/photo/' . strval($month) . '/' . strval($day) . '.jpg';}photoOfTheDay(3, 15) would yield "files/photo/3/15.jpg". The range checks would be complicated......however, the range checks above don't work, anyway: you get broken links on valid dates if the files don't exist. The script could check for the files, but it might be easier to omit the check and look for broken links in the generated pages. Edited March 3, 2008 by jcl Quote Link to post Share on other sites
bobgo2728 Posted March 3, 2008 Author Report Share Posted March 3, 2008 So do I use this code that you have given me or does it not work?The code for the day-of-the-year version would identical to the code post except that the range of the $n parameter would be [0,365] instead of [1,31].The code for the day-of-the-month would be something likefunction photoOfTheDay($month, $day){ return 'files/photo/' . strval($month) . '/' . strval($day) . '.jpg';}photoOfTheDay(3, 15) would yield "files/photo/3/15.jpg". The range checks would be complicated......however, the range checks above don't work, anyway: you get broken links on valid dates if the files don't exist. The script could check for the files, but it might be easier to omit the check and look for broken links in the generated pages. Quote Link to post Share on other sites
jcl Posted March 4, 2008 Report Share Posted March 4, 2008 So do I use this code that you have given me or does it not work?It seems to work. Quote Link to post Share on other sites
bobgo2728 Posted March 4, 2008 Author Report Share Posted March 4, 2008 I am just not following your code. I mean if you can edit what I gave the 1st time and show me the complete code so I can see it exactly what it needs to look like.So do I use this code that you have given me or does it not work?It seems to work. Quote Link to post Share on other sites
jcl Posted March 5, 2008 Report Share Posted March 5, 2008 Month and day version:<?phpfunction photoOfTheDay($month, $day){ return 'files/photo/' . strval($month) . '/' . strval($day) . '.jpg';}$date = getdate();$photo = photoOfTheDay($date[month], $date[mday]);?><center> <img src="<?php echo $photo ?>"></center>Day of the year version:<?phpfunction photoOfTheDay($day){ return 'files/photo/' . strval($day) . '.jpg';}$date = getdate();$photo = photoOfTheDay($date[yday]);?><center> <img src="<?php echo $photo ?>"></center> Quote Link to post Share on other sites
bobgo2728 Posted March 5, 2008 Author Report Share Posted March 5, 2008 OK got it, now what do I call the images and what folders would I or need to put them into.Month and day version:<?phpfunction photoOfTheDay($month, $day){ return 'files/photo/' . strval($month) . '/' . strval($day) . '.jpg';}$date = getdate();$photo = photoOfTheDay($date[month], $date[mday]);?><center> <img src="<?php echo $photo ?>"></center>Day of the year version:<?phpfunction photoOfTheDay($day){ return 'files/photo/' . strval($day) . '.jpg';}$date = getdate();$photo = photoOfTheDay($date[yday]);?><center> <img src="<?php echo $photo ?>"></center> Quote Link to post Share on other sites
jcl Posted March 5, 2008 Report Share Posted March 5, 2008 (edited) The script can be changed to whatever you need. The month and day version above uses "files/photo/<month>/<day>.jpg" where <month> and <day> are integers in the ranges [1,12] and [1,31], resp. The day of the year version uses "files/photo/<day>.jpg" where <day> is an integer in the range [0,365]. If you use either script, you might want to fix the inconsistent pluralization of "files" and "photo". I don't know why I did that. Edited March 5, 2008 by jcl Quote Link to post Share on other sites
bobgo2728 Posted March 5, 2008 Author Report Share Posted March 5, 2008 OK but is there an easy way also to add in a calendar view below it with thumbnails?The script can be changed to whatever you need. The month and day version above uses "files/photo/<month>/<day>.jpg" where <month> and <day> are integers in the ranges [1,12] and [1,31], resp. The day of the year version uses "files/photo/<day>.jpg" where <day> is an integer in the range [0,365]. If you use either script, you might want to fix the inconsistent pluralization of "files" and "photo". I don't know why I did that. Quote Link to post Share on other sites
jcl Posted March 5, 2008 Report Share Posted March 5, 2008 OK but is there an easy way also to add in a calendar view below it with thumbnails?No idea. Quote Link to post Share on other sites
bobgo2728 Posted March 6, 2008 Author Report Share Posted March 6, 2008 OK because that is also what I am looking for as well.OK but is there an easy way also to add in a calendar view below it with thumbnails?No idea. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.