FRIHOST • FORUMS • SEARCH • FAQ • TOS • BLOGS • COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


day image





megamass
i am searching for sricpt witch changes picture every day. i searched and found just these which changes pics on every refresh. waiting for help. ( it can be php script or javascript)
jasperlevink
Do you want the pics to be changed every day of the week, every day of the month or just random?

How many images do you have?
megamass
i would like it would change once a week. i have about 20 images now.
jasperlevink
you could do something like this:

Code:


<? $a = 20; // Number of images should be named img1.jpg till img20.jpg
?>
<a href="img<? echo (string) date("W")%$i; ?>.jpg



I didn't have the time to test it. So please tell me if it doesn't work

Grtz.
megamass
doesnt work. i tried to change to
Code:
<? $a = 20; // Number of images should be named img1.jpg till img20.jpg?>
<a href="img<? echo (string) date("W")%$i; ?>.jpg">

but this also didnt help
BlackSkad
Hey, try using $a instead of $i in the second line. Keep track of your variables Wink
Oh, and your ?> is commented now, so the parser won't see it and think your link is php too.
Also use <?php instead of <?, this to avoid confusion with xml...

BlackSkad
megamass
doesnt work Confused sorry for waiting so long
kamote
Try searching in dynamicdrive.com there are lot of scripts that
could be found from there.
sonam
Ok, try this. Create one new folder and put inside rotator.php and day.txt. Also put in this folder subfolder images. Rename your images like 1-anything.jpg, 2-anything.gif, 3-anything.png, etc. Only numbers is important. In day.txt type any number less then 26 and image name one before you want to see next tomorrow. Then include rotator.php on your PHP page. I hope so it will work. Sorry, I haven't time for better explain.

rotator.php

Code:
<?php
$day = date("z"); // day in year
$file = file("day.txt");
list($oldDay, $oldImage) = explode("|", $file[0]);
list($num, $image) = explode("-", $oldImage);
$dir = "images";

// check old and new day
if($day != $oldDay) {
// open and read image folder
$openDir  = opendir($dir);
while (false !== ($fileNames = readdir($openDir))) {
          $allfiles[] = $fileNames;   
    }
   
// kick out anything what is not file
for($o = 0; $o < count($allfiles); $o++) {
            list($front, $ext) = explode(".", $allfiles[$o]);
           if($front == "" || $ext == "") {
                continue;
           } else {
                $images[] = $allfiles[$o];
           }
      }
      
asort($images, SORT_NUMERIC);
$sortImages = array_values($images);
$count = count($sortImages);
for($i = 0; $i < $count; $i++) {       
       if (strpos($sortImages[$i], $image) > 0 && $i < $count-1) {
            $newImage = $sortImages[$i+1];
          break;
      } else {
            $newImage = $sortImages[0];
      }
}

// write new data in day.txt
      $newData = $day . "|" . $newImage;
      $fileNew = fopen("day.txt", "wb");
      fwrite($fileNew, $newData);
      fclose($fileNew);

     $display = include_once("$dir/$newImage");
} else {
     $display = include_once("$dir/$oldImage");
}

echo $display;   
?>



day.txt

Code:
25|1-example.jpg
Related topics
How many hours do you spend on games each day?
Image Magick on vacation?
Future FriHost April Fool's Day Suggestions
Describe your typical day at work
[Close This Thread Please]
What programs MUST you have open?
Fasle Perfection Image
RMB Arcade
Giveaway Of The Day - Un Logiciel Gratuit Par Jour!
Imgur the simple image sharer
Image hosting issue
30-day music challenge
Day 05 – Quick nifty hacks you’re proud of
create a system image
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.