View Full Version : Slideshow won't work with PHP 5

03-06-2007, 08:22 PM

I wrote this slideshow script for a real estate site a few years back and recently altered it slightly for a used vehicle site, worked just fine until the host upgraded the server to PHP 5.
This script resides in the same directory as the photos (up to 5). It takes the names of files beginning with "t_" (thumbnails) and puts them into an array. Then does its thing.
PHP 5 appears to be screwing up the count.

Can anyone tell me why this is so?

body { margin: 0px; }
a { font-family: arial; font-size: 12px; font-weight: normal; color: white; text-decoration: none; }
a:hover { font-face: arial; font-size: 12px; font-weight: normal; color: white; text-decoration: underline; }
<body bgcolor="#666666">
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr><td colspan="2" align="right">
<a href="javascript:window.close();"><img src="../../images/close.gif" width="105" height="18" border="0"></a></td></tr>
<tr><td colspan="2" align="center">

if(!isset($start)) $start = 0;
$pics = Array();
$number = "1";
$handle = opendir(".");
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (!strstr($file, "t_")) {
$pics[] = $file; }
$total = (count($pics) - 1);
for($z=0; $z < ($number); $z++) {
$thu = $z + $start;
if ($pics[$thu] != "")

$size = getimagesize("$pics[$thu]");

echo "<img src=\"". $pics[$thu]. "\" border=1 width=\"$size[0]\" height=\"$size[1]\">";
echo "</td></tr>";
echo "<tr><td align='left'>";
if($start > 0)
echo "<a href=\"" . $PHP_SELF . "?start=" . ($start - 1) . "\"><img src=\"../../images/prev.gif\" border=\"0\"></a><BR>\n";
echo "</td><td align='right'>";
if($start > ($total)) {
echo "";
} else {
if($total > ($start + 1))
echo "<a href=\"" . $PHP_SELF . "?start=" . ($start + 1) . "\"><img src=\"../../images/next.gif\" border=\"0\"></a><BR>\n"; }
echo "</td></tr></table>";

Suggestions would be appreciated as it has me beat.

03-06-2007, 08:45 PM
Replace $PHP_SELF with $_SERVER['PHP_SELF'] first, but that's not your problem if the count is messed up.

03-06-2007, 09:40 PM
I have the following script which I have written long time ago...which does something similar to what you are after. You are welcome to modify it and use it for your own purpose.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<title>Slide Show</title>
$image_dir = "images/"; // directory to read
$image_array = array();

array of not allowed elements
thumb.db is usually created in windows by the OS (usually hidden)
$not_allowed = array( ".", "..", "thumb.db" );

$handler = opendir( $image_dir );

while( $file = readdir( $handler ) ) {
if( !in_array( $file, $not_allowed ) && !is_dir( $file ) ) {
array_push( $image_array, $file );
} //-- ends if
} //-- ends while loop

closedir( $handler );

<script type="text/javascript">
// create an array in JavaScript
var image_array = new Array( <?php echo count( $image_array ); ?> );

// start populating the array with images read from PHP
for( $i = 0; $i < count( $image_array ); $i++ ) {
// temp image etc.
var temp_image = new Image();
temp_image.src = <?php echo "'". $image_dir . $image_array[ $i ] . "'"; ?>;
image_array[ <?php echo $i; ?> ] = temp_image;
} //-- ends for loop

var currentImg = 0; // curent image in display
var id_reference ="slide_show_replace"; // id reference of the img tag
function slideShow( ) {
if( currentImg == image_array.length )
currentImg = 0;
window.document.getElementById( id_reference ).src = image_array[ currentImg ].src;
setTimeout( "slideShow()",1000 );
} //-- ends slideShow

<body onload = "javascript: slideShow();">
<img src="<?php echo $image_dir . $image_array[0];?>" alt="slideshow" id="slide_show_replace" />

Let me know if there are any problems with the script.


03-06-2007, 09:47 PM
I'm not quite sure how it worked before you upgraded...

if (!strstr($file, "t_")) {
$pics[] = $file; }

will add an entry to $pics[] when t_ isn't present in the filename...the opposite of what you want, no?

You initialise $number to equal "1" (not sure why it's a string...but that won't matter much) and then use it in a loop comparison:

for($z=0; $z < ($number); $z++) {

which will cause the loop to always just run once...odd?

03-06-2007, 10:31 PM

It will work either way, add the images or add the thumbs to $pics[].
I'll see if I can find where I have used it so you can see how it worked.

If not I will put it up somewhere else.

03-06-2007, 11:19 PM
I noticed I had left 1 line out, all this did was effect the last $pics[] in the array.

I have put it up at...

It is working here except for the last vehicle in the list.

03-08-2007, 09:50 AM
The script you left here is nothing like the script in the original post.
Looks as though there is nobody who can help with an answer to my question comes by here.
Thanks anyway

03-08-2007, 12:17 PM
If someone has upgraded there php is iot not possible that there is now a problem with the gd functions have you checked the GD info on the server?

03-08-2007, 06:02 PM

The character who looks after the server blocked the use of phpinfo() as soon as I questioned the setup (reckons it's a security risk). Won't even answer my questions, reckons I am not his client so I don't count.

03-08-2007, 06:19 PM
$total = (count($ifiles) - 1);

What is $ifiles?


03-08-2007, 07:19 PM

Been looking at this too long, $ifiles was a typo when I added a line i had missed.