slideshow.phps

<?php
 
// Data File : This file need to be writeable
$file_name = "imagesdata.txt";
 
  // check existance of file
    $try = file_exists($file_name);
  if (!$try) {
    echo "<p>I'm sorry, but I could not open the file: ".$file_name."!";
    exit;
  }
 
$filecnts = file($file_name);
 
$count = count($filecnts)-1;
 
if ($count <= 0){
 
echo "There are currently no images in the slideshow.
<br>Please edit the ".$file_name." file and add images to the slideshow.";
 
}else{
 
$rows=1; //how many results to show
 
$offset = $_GET['offset'];
 
if ((!$offset) || ($offset < 1)){ //if offset not set or less than one, set to one
            $offset=1;
}
 
$nextoffset=$offset+$rows;
$prevoffset=$offset-$rows;
 
$page = $_GET['page'];
 
if(!isset($page)){ $page=1; $stoprefresh=0; }
 
//to read the file use:
$fp2= fopen($file_name, "r");
 
$line_cnt=0;
 
while ($imageinfo=fgets($fp2,1024)){
if ($line_cnt == $page){
    $right_line = $imageinfo;
    list($imagepath, $imagewidth, $imageheight, $titletop, $titlebot, $credit)= explode("*",$right_line);
    break;
   }
   $line_cnt++;
}
 
fclose($fp2);
 
$stoprefresh = $_GET['stoprefresh'];
 
if($stoprefresh !=1){
// automatically refresh page x number of seconds when stoprefresh is not true (1)
 
if($page !=$count){
echo "<meta http-equiv=refresh content=\"5;URL=$PHP_SELF?page=".$nextoffset."&offset=".$nextoffset."&stoprefresh=".$stoprefresh."\">";
}else{
echo "<meta http-equiv=refresh content=\"5;URL=$PHP_SELF?page=1&offset=1&stoprefresh=".$stoprefresh."\">";   
}
 
}   
 
?>
 
        <table border="0" valign="top" cellspacing="10">
                <tr><td valign="top" colspan="5">
                <span class="head">Slideshow: Random Images</span>
                <img src="/images/blancopix.gif" width=1 height=10><br>
 
                <span class="smhead"><? echo $titletop; ?></span>
                <br><img src="/images/blancopix.gif" width=1 height=10><br>
 
    <img src="<? echo $imagepath; ?>" width="<? echo $imagewidth ?>" height="<? echo $imageheight ?>"><br>
 
                 <span class="content"><? echo $titlebot; ?>
 
                   <img src="/images/blancopix.gif" width=1 height=20><br>
                   Photo credit: <? echo $credit; ?>                      .
 
                      <br><img src="/images/blancopix.gif" width=1 height=10><br>
 
<?php
 
echo 'count '.$count;
echo '<br>prev '.$prevoffset;
echo '<br>next '.$nextoffset;
 
if (($count < $nextoffset) && ($prevoffset < 1)):
    $winners .= "";   
 
elseif ($prevoffset < 1):
$winners .= "<p><a href=\"$PHP_SELF?page=$nextoffset&offset=$nextoffset&stoprefresh=$stoprefresh\">next&nbsp;</a>";   
 
elseif ($count < $nextoffset):
$winners .= "<p><a href=\"$PHP_SELF?page=$prevoffset&offset=$prevoffset&stoprefresh=$stoprefresh\">prev&nbsp;</a>";   
 
else:
$winners .= "<p><a href=\"$PHP_SELF?page=$prevoffset&offset=$prevoffset&stoprefresh=$stoprefresh\">prev&nbsp;|&nbsp;</a>
<a href=\"$PHP_SELF?page=$nextoffset&offset=$nextoffset&stoprefresh=$stoprefresh\">next</a>";
 
endif;
print ($winners);
 
?>
 
<br><img src="/images/blancopix.gif" width=1 height=20><br>
 
<a class="link" href="<? echo "$PHP_SELF?page=".$page."&offset=".$page."&stoprefresh=1"; ?>">Stop auto refresh</a>
     <img src="/images/blancopix.gif" width=100 height=1>
<a class="link" href="<? echo "$PHP_SELF?page=".$page."&offset=".$page."&stoprefresh=0"; ?>">Start auto refresh</a>
 
<?php
 
}
 
?>