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 7 of 7
  1. #1
    Regular Coder Tyree's Avatar
    Join Date
    Sep 2003
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Vars not being passed...

    Okay, slideshow.php defines 2 variables, $array1 and $var2.

    slideshow.php is then included in header.php in the normal include manner.

    header.php contains 1 check against the existence of $array1.

    footer.php also contains 1 check against $array1 and if it exists, prints $var2.

    Even though $array1 exists and is printed by slideshow.php within itself, it fails the check by $header.php and $footer.php.

    If I just paste the code from slideshow.php into header.php rather than include it, then $array1 passes the check on header.php, but still not on footer.php.

    What’s up with that? :-D

    Here's a further description of how the files associate...
    - slideshow.php is included in header.php
    - header.php and footer.php are included in just about every other public file on the site. header.php contains all the code before the main content info of a page and footer.php everything after. You get the idea.

    I should add that the slideshow.php file is definitely being included. The jscript is printed with the php code being parsed correctly within the slideshow.php file. Where the jscript array for the images is built by the php. That's working fine and being shown correctly if I view the source of the final page in a browser.

    Below is the code for slideshow.php and subsequently the places in header.php and footer.php where variables from slideshow.php are called:

    Code:
    <?php
    	//Get image names from folder
    	$imageFileLoc = opendir($siteBasePath.'images/slideshow-images/');
    
         		while (false !== ($imageFile = readdir($imageFileLoc))) {
         			if (($imageFile != '.DS_Store') && ($imageFile != '_notes')){
    					$imageFiles[] = trim($imageFile);
    				}
    				sort($imageFiles);
    			}
    
         		closedir($imageFileLoc);
    			
    	//Setup slideshow placeholder
    	$slideShow = '<table border="0" cellpadding="0" cellspacing="0">' .
    				 '<tr>' .
    				 '<td id="VU" height=160 width=124>' .
    				 '<img src="'.$imageFiles[1].'" name="SlideShow" width=160 height=124></td>' .
    				 '</tr>' .
    				 '</table>';
    
    ?>
    <script>
    // (C) 2000 www.CodeLifter.com
    // http://www.codelifter.com
    // Free for all users, but leave in this  header
    // NS4-6,IE4-6
    // Fade effect only in IE; degrades gracefully
    
    // =======================================
    // set the following variables
    // =======================================
    
    // Set slideShowSpeed (milliseconds)
    var slideShowSpeed = 5000
    
    // Duration of crossfade (seconds)
    var crossFadeDuration = 3
    
    // Specify the image files
    var Pic = new Array() // don't touch this
    // to add more images, just continue
    // the pattern, adding to the array below
    
    <?php
    	//Get filenames from slideshow folder
    	for ($i=2; $i < count($imageFiles); $i++){
    	$picIndex = $i - 2;
    		print "Pic[".$picIndex."] = '/images/slideshow-images/".$imageFiles[$i]."';";
    	}
    ?>
    
    // =======================================
    // do not edit anything below this line
    // =======================================
    
    var t
    var j = 0
    var p = Pic.length
    
    var preLoad = new Array()
    for (i = 0; i < p; i++){
       preLoad[i] = new Image()
       preLoad[i].src = Pic[i]
    }
    
    function runSlideShow(){
       if (document.all){
          document.images.SlideShow.style.filter="blendTrans(duration=2)"
          document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
          document.images.SlideShow.filters.blendTrans.Apply()      
       }
       document.images.SlideShow.src = preLoad[j].src
       if (document.all){
          document.images.SlideShow.filters.blendTrans.Play()
       }
       j = j + 1
       if (j > (p-1)) j=0
       t = setTimeout('runSlideShow()', slideShowSpeed)
    }
    </script>
    Code:
    Header.php
    between the head tags to include the jscript:
    <?php fileInclude('/php-bin/slideshow.php'); ?>
    
    AND in the body to load the slideshow jscript if there is an array:
    <?php print ((is_array($imageFiles))? '; runSlideShow()' : ''); ?>
    
    Footer.php
    Where the slideshow is placed:
    <?php print ((is_array($imageFiles))? $slideShow : '<img src="/images/page_photo.png" />'); ?>
    Thanks!
    Matt
    Matt Tyree
    TyreeOnline
    If I didn't just "make it worse," show me some love! Hit me with the rep points! :) (The white scales icon on the left)

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Did you make your own function for including files? Can we see that function?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder Tyree's Avatar
    Join Date
    Sep 2003
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, sorry 'bout that! Forgot I had done that!

    Code:
    //Includes the file specified as $location
     function fileInclude($file){
     	global $siteBasePath;
     	include($siteBasePath.$file);
     }
    It just inserts the server's base path for me.

    Think it may be the problem?
    Matt Tyree
    TyreeOnline
    If I didn't just "make it worse," show me some love! Hit me with the rep points! :) (The white scales icon on the left)

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    It shouldn't be. Have you checked to see if the array is getting the values you want? Do a print_r($imageFiles); to see if the array was even populated.

    Also what is $siteBasePath? Is it simply $_SERVER['DOCUMENT_ROOT']? If it is have you checked to see what that returns? If it returns what I think it does then this line
    PHP Code:
    $imageFileLoc opendir($siteBasePath.'images/slideshow-images/'); 
    tries to open this directory
    [php]$imageFileLoc = opendir('home/user/public_htmlimages/slideshow-images/');
    Usually the trailing forward slash isn't returned.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Regular Coder Tyree's Avatar
    Join Date
    Sep 2003
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, the $imageFiles array is spit out into a javascript array. That all happens within the slideshow.php file. That's definitely working.

    I switched all my includes to:
    Code:
    include($siteBasePath.'/somepath/somefile.php');
    The $siteBasePath is defined as
    Code:
    $siteBasePath = '/var/www/vhosts/calvarychapelac.com/httpdocs/';
    inside another include file (include.php) that is included on every page at the top with the full path.
    Code:
    include('/var/www/vhosts/calvarychapelac.com/httpdocs/php-bin/include.php');
    Now everything is working fine that I got rid of the function.

    Someone else told me I couldn't use the include function inside another function. So, I just dropped it and stuck the base path in at each include statement (what I was trying to avoid).
    Matt Tyree
    TyreeOnline
    If I didn't just "make it worse," show me some love! Hit me with the rep points! :) (The white scales icon on the left)

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You could easily do something like
    PHP Code:
    include($_SERVER['DOCUMENT_ROOT'].'/php-bin/include.php'); 
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Regular Coder Tyree's Avatar
    Join Date
    Sep 2003
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Awesome! Thanks!

    I'm still just a young padawan to the php.
    Matt Tyree
    TyreeOnline
    If I didn't just "make it worse," show me some love! Hit me with the rep points! :) (The white scales icon on the left)


  •  

    Posting Permissions

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