Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Apr 2006
    Location
    Queensland Oz
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    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.

  • #3
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    865
    Thanks
    7
    Thanked 29 Times in 28 Posts
    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

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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

  • #5
    New Coder
    Join Date
    Apr 2006
    Location
    Queensland Oz
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #6
    New Coder
    Join Date
    Apr 2006
    Location
    Queensland Oz
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #7
    New Coder
    Join Date
    Apr 2006
    Location
    Queensland Oz
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #8
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    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.

  • #9
    New Coder
    Join Date
    Apr 2006
    Location
    Queensland Oz
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #10
    Regular Coder
    Join Date
    Oct 2006
    Location
    Bristol
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  • #11
    New Coder
    Join Date
    Apr 2006
    Location
    Queensland Oz
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Alex,

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •