We help IT Professionals succeed at work.

Trying to find out what the value of a variable is...

Simon336697
Simon336697 asked
on
288 Views
Last Modified: 2008-03-10
Hi!
Im attempting to find out what the value of $int_pic is in the following code.
Any help greatly appreciated.

<script type="text/javascript">
var galleryarray = new Array();

<?php
$images = glob('panorama/*.jpg');
$indx = 0;
$init_pic = $images[array_rand($images)];
foreach( $images AS $pic)
{
      echo "galleryarray[$indx]='$pic';
";
            $indx++;
}
?>
</script>

=======================================================

Just to let you know, the path where this script is located is:

c:\wamp\www\mediawiki

with the panorama folder being in

c:\wamp\www\mediawiki\panorama

There are image files in the above folder.

Thank you.
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi glcummins!
Thanks so much for your help on this.
Ive been working on this very problem for days now.

gl, is $init_pic the FULL PATH to the image filename, or JUST the filename?

The reason I ask is that, and I so much hope you can help me....

On initial load of my page, the image is displayed properly.....with a path pointing to:

http://fire/mediawiki/skins/gumax/panorama/vervet_monkey.jpg

But on subsequent polling, the returned image name has a value of:

http://fire/mediawiki/index.php/panorama/qnljis_weimaraner.jpg

which the page cant find to load the image

If I hard code the path to the image, it works.

Here is the code that Im having problems with :>)

==================================================================

<script type="text/javascript">
function opacity(id, opacStart, opacEnd, millisec) {
      //speed for each frame
      var speed = Math.round(millisec / 100);
      var timer = 0;

      //determine the direction for the blending, if start and end are the same nothing happens
      if(opacStart > opacEnd) {
            for(i = opacStart; i >= opacEnd; i--) {
                  setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
                  timer++;
            }
      } else if(opacStart < opacEnd) {
            for(i = opacStart; i <= opacEnd; i++)
                  {
                  setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
                  timer++;
            }
      }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
      var object = document.getElementById(id).style;
      object.opacity = (opacity / 100);
      object.MozOpacity = (opacity / 100);
      object.KhtmlOpacity = (opacity / 100);
      object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
      //if an element is invisible, make it visible, else make it ivisible
      if(document.getElementById(id).style.opacity == 0) {
            opacity(id, 0, 100, millisec);
      } else {
            opacity(id, 100, 0, millisec);
      }
}

function blendimage(divid, imageid, imagefile, millisec) {
      var speed = Math.round(millisec / 100);
      var timer = 0;
      
      //set the current image as background
      document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
      
      //make image transparent
      changeOpac(0, imageid);
      
      //make new image
      document.getElementById(imageid).src = imagefile;

      //fade in image
      for(i = 0; i <= 100; i++) {
            setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
            timer++;
      }
}

function currentOpac(id, opacEnd, millisec) {
      //standard opacity is 100
      var currentOpac = 100;
      
      //if the element has an opacity set, get it
      if(document.getElementById(id).style.opacity < 100) {
            currentOpac = document.getElementById(id).style.opacity * 100;
      }

      //call for the function that changes the opacity
      opacity(id, currentOpac, opacEnd, millisec)
}


</script>


<script type="text/javascript">
var galleryarray = new Array();

<?php
$images = glob('panorama/*.jpg');
$indx = 0;
$init_pic = $images[array_rand($images)];
foreach( $images AS $pic)
{
      echo "galleryarray[$indx]='$pic';
";
            $indx++;
}
?>

var tm1=2,tm2=15,tm3=1;
function step1()
{
   setTimeout("step2()",tm1*1000);
}
function step2()
{
   shiftOpacity('blendimage', tm3*1000);
   setTimeout("step3()",(tm2+tm3)*1000);
}
function step3()
{
  var rand=Math.floor(Math.random()*galleryarray.length);
   shiftOpacity('blendimage', tm3*1000);
   setTimeout("step2()",(tm1+tm3)*1000);
setTimeout("document.getElementById('blendimage').src = '"+galleryarray[rand]+"'", tm3*1000);
}
window.onload=step1;
</script>

<div id="gumax-site-logo">
    <?php $sitelogo = $this->data['stylepath'] . '/' . $this->data['stylename'] . '/' . $init_pic; ?>    
<img src="<?php echo $sitelogo ?>" style="width: 928px; height: 147px; border: 1 none; filter: alpha(opacity=20); -moz-opacity: 20; opacity: 0;" id="blendimage""/>          
</div>
</div>

===============================================================
My php file (GuMax.php) is located in:
/var/www/html/mediawiki/skins/GuMax.php

My images folder called panorama is:
/var/www/html/mediawiki/panorama

In my code, I have the panorama folder pointing to:
$images = glob('panorama/*.jpg');
which is in:
/var/www/html/mediawiki/panorama

Now the problem........
When the page loads, it loads the firs image fine, but its getting it from:
http://fire/mediawiki/skins/gumax/panorama/namibie_desert.jpg
which is
/var/www/html/mediawiki/skins/gumax/panorama
which is NOT what I have in my code.
On subsequent images, it is trying to find:
http://fire/mediawiki/index.php/panorama/vervet_monkey.jpg
which is:
/var/www/html/mediawiki/panorama
Again not correct, and this time, the page displays a red cross.
The quandry I have is that the php code where it randomly finds an image IS actually doing this.
It is just having a problem with displaying the correct path on the page on load, so that the image doesnt display and the path is incorrect.

what I have to do somehow is get the path pointing to:

http://fire/mediawiki/skins/panorama PLUS image_name_variable, so the path it will load is:

http://fire/mediawiki/skins/panorama/imagevariable.jpg

Something in my code is not correct in outputting or echoing the wrong path in the following section:

    <?php $sitelogo = $this->data['stylepath'] . '/' . $this->data['stylename'] . '/' . $init_pic; ?>    
<img src="<?php echo $sitelogo ?>" style="width: 928px; height: 147px; border: 1 none; filter: alpha(opacity=20); -moz-opacity: 20; opacity: 0;" id="blendimage""/>          
</div>

Take 2........

On first load

http://fire/mediakwiki/skins/panorama/death_valley_flowers_panorama.jpg

After around 15 seconds, I get:
http://fire/mediawiki/index.php/skins/panorama/death_valley_flowers_panorama.jpg

glob() returns only the filename, not the full path.

Author

Commented:
gl!
Ive honed in on what the problem is and hope you can help...you are my last resort.....

Im trying to return at a set interval, different images from the panorama folder, and to load them into the div gumax-site-logo

If I just echo out the $init_pic variable into the div as below....
<div id="gumax-site-logo">    
<img src="<?php echo $init_pic ?>" style="width: 928px; height: 147px; border: 1 none; filter: alpha(opacity=20); -moz-opacity: 20; opacity: 0;" id="blendimage""/>          
</div>

The path to the image is:
http://fire/mediawiki/index.php/skins/panorama/morocco.jpg
This would load successfully if it were not for the 'index.php' part in the filename above.
If somehow we can strip out the index.php in the above when echoing out the $init_pic variable, you have solved the hardest problem I have ever had to face.

So, the $init_pic is still required because it is returning random image names, but its returning the full path including the path which is stuffing things up....the index.php.



http://fire/mediawiki/index.php/skins/panorama/mr_rhino_1.jpg

Author

Commented:
Thx for your help :>)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.