Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-06-2007, 08:22 PM   PM User | #1
ozlad
New Coder

 
Join Date: Apr 2006
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
ozlad is an unknown quantity at this point
Slideshow won't work with PHP 5

Hi,

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?

PHP Code:
<html>
<head>
<style>
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; }
</style>
</head>
<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">

<?php
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; }
  }
}
closedir($handle);
$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>";
?>
<body>
</html>
Suggestions would be appreciated as it has me beat.

Last edited by ozlad; 03-08-2007 at 07:16 PM.. Reason: typo when I added the missing line
ozlad is offline   Reply With Quote
Old 03-06-2007, 08:45 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,604
Thanks: 2
Thanked 399 Times in 392 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Replace $PHP_SELF with $_SERVER['PHP_SELF'] first, but that's not your problem if the count is messed up.

Last edited by Inigoesdr; 03-06-2007 at 08:47 PM..
Inigoesdr is offline   Reply With Quote
Old 03-06-2007, 09:40 PM   PM User | #3
ess
Regular Coder

 
Join Date: Oct 2006
Location: United Kingdom
Posts: 865
Thanks: 7
Thanked 29 Times in 28 Posts
ess will become famous soon enough
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.

PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Slide Show</title>
<?php 
$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
<?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;
<?php
//-- 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;
    currentImg++;
    setTimeout( "slideShow()",1000 );
} //-- ends slideShow

</script>
</head>
<body onload = "javascript: slideShow();">
<h1>SlideShow</h1>
<img src="<?php echo $image_dir $image_array[0];?>" alt="slideshow" id="slide_show_replace" />
</body>
</html>
Let me know if there are any problems with the script.

Cheers,
Ess
ess is offline   Reply With Quote
Old 03-06-2007, 09:47 PM   PM User | #4
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
I'm not quite sure how it worked before you upgraded...
PHP Code:
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:
PHP Code:
for($z=0$z < ($number); $z++) { 
which will cause the loop to always just run once...odd?
__________________
My thoughts on some things: http://codemeetsmusic.com
And my scrapbook of cool things: http://gjones.tumblr.com
GJay is offline   Reply With Quote
Old 03-06-2007, 10:31 PM   PM User | #5
ozlad
New Coder

 
Join Date: Apr 2006
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
ozlad is an unknown quantity at this point
GJay

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.
ozlad is offline   Reply With Quote
Old 03-06-2007, 11:19 PM   PM User | #6
ozlad
New Coder

 
Join Date: Apr 2006
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
ozlad is an unknown quantity at this point
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...
http://hilited.com/qah/vehicles.php

It is working here except for the last vehicle in the list.
ozlad is offline   Reply With Quote
Old 03-08-2007, 09:50 AM   PM User | #7
ozlad
New Coder

 
Join Date: Apr 2006
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
ozlad is an unknown quantity at this point
ess,
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
ozlad is offline   Reply With Quote
Old 03-08-2007, 12:17 PM   PM User | #8
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,466
Thanks: 90
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
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?
__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Old 03-08-2007, 06:02 PM   PM User | #9
ozlad
New Coder

 
Join Date: Apr 2006
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
ozlad is an unknown quantity at this point
timgolding,

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.
ozlad is offline   Reply With Quote
Old 03-08-2007, 06:19 PM   PM User | #10
Alex!
Regular Coder

 
Join Date: Oct 2006
Location: Bristol
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Alex! is an unknown quantity at this point
Quote:
Originally Posted by ozlad View Post
$total = (count($ifiles) - 1);
What is $ifiles?

Alex
__________________
Give me Rep if I was helpful and ignore if I wasn't ;)

http://www.google.com <--use this before asking

Nominate a Helpful Member

Alex! is offline   Reply With Quote
Old 03-08-2007, 07:19 PM   PM User | #11
ozlad
New Coder

 
Join Date: Apr 2006
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
ozlad is an unknown quantity at this point
Alex,

Been looking at this too long, $ifiles was a typo when I added a line i had missed.
ozlad is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:10 AM.


Advertisement
Log in to turn off these ads.