Jump to content

PHP Slideshow


Recommended Posts

I was looking for a simple slideshow script to include in my webpage, and found this:

 

<?php

*******************************************************************************
                                  CODE SECTION
******************************************************************************/

// look for picture files in current directory and add them to photos array
$current_dir = opendir(".");
while ($file = readdir($current_dir)) {
    if (eregi("(\.jpg|\.gif|\.png)$", $file)) $photos[] = $file;
}
closedir($current_dir);

// check to see if images were found in directory; if no images were found,
// alert user through $title on webpage
if ($photos == null) $title = "There are no pictures in this directory!  ";
// images were found; sort them
else sort($photos);

// read title of slideshow from title.txt
if (file_exists('title.txt')) { 
    $title_file = file('title.txt'); 
    $title = $title.$title_file[0];
}
// no title.txt file was found; alert user through $title on webpage
else $title = $title."You did not supply a title.txt file!";
   
// get total number of pictures 
$num_pics = count($photos);

// if image number is not specified, set it to the first image
if (empty($image)) $image = '0';

// if user is on the last image or if the image number specified is greater than
// the number of pics available in the directory, start user at first image
if (($image == $num_pics) || ($image > $num_pics)) $image = '0';

// setup the link for the next image
$next = $image + 1;

// setup the link for the previous image
if ($image == '0') $prev = $num_pics - 1;
else $prev = $image - 1;

/*******************************************************************************
                                   PRINT HTML
******************************************************************************/

print <<< PRINT_PAGE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" media="screen" href="http://justinblanton.com/screen.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://justinblanton.com/syndicate/" />
<meta name="description" content="life. technology. politics." />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<title>Justin Blanton | Photos | $title</title>
</head>
<body>
<div id="container">
<div id="photos">
<h3>$title <span class="tiny">($next of $num_pics)</span></h3>
<a href="?image=$next"><img src="$photos[$image]"></a>
<br />
<p><a href="?image=$prev">« prev</a> · <a href="http://justinblanton.com/photos/">photos home</a> · <a href="?image=$next">next »</a></p>
</div>
</div>
</body>
</html>
PRINT_PAGE;
?>

 

on http://justinblanton.com where it seems to work fine, but for some reason when I tried to get it working on my site it continually calls the same image - see here.

 

My very limited php knowledge has run out, and any thoughts as to why it wouldn't be working would be greatly appreciated.

 

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/54218-php-slideshow/
Share on other sites

  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.