• Welcome! The TrekBBS is the number one place to chat about Star Trek with like-minded fans.
    If you are not already a member then please register an account and join in the discussion!

Need some help with a php script

Koinek

Vice Admiral
Admiral
Disclaimer - I do not know how to code in PHP or any other language. I'm just an intuitive computer user who can tinker with existing code and make it work for me.

So, I'm working with an existing script in php that I found online. I originally used it to display a random image from a group that I uploaded online. Now, I'm trying to integrate javascript rollover code, into the php. I've succeeded except that it has invalidated the java's ability to preload the rollover image.

Take a look at the following code and tell me if there is a line I can add to have it preload the rollover image:
Code:
<?php

/*

  Author: Dan Benjamin - [URL]http://hivelogic.com/[/URL]

  Copyright (c) 2004 Automatic, Ltd. All Rights Reserved.

  THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF 
  ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY 
  IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR 
  PURPOSE OR NONINFRINGEMENT.  

  IN NO EVENT SHALL DAN BENJAMIN, A LIST APART, OR AUTOMATIC, LTD. BE LIABLE
  FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR
  LOST PROFITS ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER
  ARISING, INCLUDING NEGLIGENCE), EVEN IF DAN BENJAMIN, A LIST APART, OR
  AUTOMATIC, LTD. IS AWARE OF THE POSSIBILITY OF SUCH DAMAGES.

*/



  # file containg your image descriptions

  $IMG_culCONFIG_FILE = 'culimages2.ini';



  # You shouldn't need to change anything below this point

  function showculImage( $ini=null ) {
    global $IMG_culCONFIG_FILE;
    # if no custom ini file has been specified, use the default
    $ini_file = $ini ? $ini : $IMG_culCONFIG_FILE;
    # read the config file into an array or die trying
    $images = @parse_ini_file($ini_file,true);
    if (! $images) {
      die('Unable to read ini file.');
    }
    # pick a random image from the parsed config file
    $img = array_rand($images);
    # get the selected image's css id if one exists
    $id = $images[$img]['id'] ?
      sprintf( ' id="%s" ', $images[$img]['id'] ) :
      '';
    # get the selected image's css class if one exists
    $class = $images[$img]['class'] ?
      sprintf( ' class="%s" ', $images[$img]['class'] ) :
      '';
    # get selected image's dimensions
    $size = @getimagesize( $images[$img]['src'] );
    # if an url was specified, output the opening A HREF tag
    if ( $images[$img]['url'] ) {
      printf(
        '<a href="%s" target="_blank" onmouseover="MM_swapImage(%s)" onmouseout="MM_swapImgRestore()">',
        $images[$img]['url'],
        $images[$img]['rol']
      );
    }
    # output the IMG tag
    printf(
      '<img src="%s" alt="%s" name="culimg" %s border="0" id="culimg" />',
      $images[$img]['src'],
      $images[$img]['alt'],
      $size[3]
    );
    # if an url was specified, output the closing A HREF tag
    if ( $images[$img]['url'] ) {
      echo('</a>');
    }
  }


?>
And a sample piece from the .ini file that lists the images for the php files' use:
Code:
[Cul1]
src   = mywebpage.com/cul01.jpg
rol   = 'culimg','','mywebpage.comcul/20.jpg',1
alt   = Qi Shu Fang Peking Opera
url   = [URL]http://www.qishufang.com[/URL]
As you can see there is some very ugly java splicing involved (done by me) but it works.

I'm hoping there is a way I can add a "lod = mywebpage.comcul/20.jpg" into the .ini and have the php pull that to preload the image. But like I said before, I can't code in php.:alienblush:
 
does the lod=xxxx go into the <a href statement? I cant remember...

This assumes it goes in the <img> tag and does NOT test to see if there actually is a lod set in the ini

Code:
   printf(
      '<img src="%s" alt="%s" name="culimg" %s border="0" id="culimg" lod="%s" />',
      $images[$img]['src'],
      $images[$img]['alt'],
      $size[3],
      $images[$img]['lod']
    );
 
Errr I didn't know "lod" was a tag or a piece of code. That was just a line/variable name I gave to the place where I could specify the file to be pre-loaded.

I'm just looking to specify the rollover image in the .ini and place something in the php where by it can be pre-loaded.
 
Lod would be replaced in the code by whatever call you are using to do the preloading.

It might look like the below, but i cant say because your not showing us the preloading script you said was working.

<img src="%s" alt="%s" name="culimg" %s border="0" id="culimg"
ONMOUSEOVER=loadimage("%s");
/>
 
You shouldn't need php for a preloader...

Use dreamweavers javascript preloader...

<body onload="MM_preloadImages('images/index_r06_c01_f2.gif','images/searchbutton_f2.gif','images/whatnew_r15_c1_f2.gif',etc...">

+

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a.indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
}


 
If you are not already a member then please register an account and join in the discussion!

Sign up / Register


Back
Top