Simon336697
asked on
An Image variable
Hi everyone!
I have a php file that has the following statement:
<img src=" <?php echo 'http://localhost/mediawiki/skins/panorama/death_valley_flowers_panorama.jpg' ?>" style="width: 928px; height: 147px; border: 1 none; filter: alpha(opacity=20); -moz-opacity: 0; opacity: 0;" id="blendimage""/>
When the page loads, I can see the image 'death_valley_flowers_pano rama.jpg'
The folder where this image is, is in:
C:\wamp\www\mediawiki\skin s\panorama
and there are many images in here.
A variable called $init_pic holds the full path to the location of the panorama folder, and randomly returns an image from that folder.
But if I define img src like the following.....
<img src=" <?php echo 'http://localhost/mediawiki/skins/panorama/' . $init_pic ?>
What $init_pic expands out to is:
C:/wamp/www/mediawiki/skin s/panorama /death_val ley_flower s_panorama .jpg
That is the FULL PATH to the random image.
So I end up with img src expanding out to be:
http://localhost/mediawiki/skins/panorama/C:/wamp/www/mediawiki/skins/panorama/death_valley_flowers_panorama.jpg
which is wrong...it cant find that.
If I place in a hardcoded image path as follows:
<img src=" <?php echo 'http://localhost/mediawiki/skins/panorama/' . 'death_valley_flowers_pano rama.jpg' ?>
This loads fine.
But I need the $init_pic variable in there so that the image can change.
The only problem is that with $init_pic in there, I get the following:
http://localhost/mediawiki/skins/panorama/C:/wamp/www/mediawiki/skins/panorama/death_valley_flowers_panorama.jpg
I need somehow to make img src look like the following:
<img src=" <?php echo 'http://localhost/mediawiki/skins/panorama/' . 'death_valley_flowers_pano rama.jpg' ?>
but where 'death_valley_flowers_pano rama.jpg' is actually $init_pic, so that the images will change.
$int_pic returns the full path to the image.
Is there any way to first return that full path, then cut off everything from the front, to just leave the resulting image name?
So, in other words, is there a function or something that can do the following....
<img src=" <?php echo 'http://localhost/mediawiki/skins/panorama/' . '$int_pic?>
Then before img src is set to this, as this will be wrong....
Trim off the expanded $int_pic variable
from
C:/wamp/www/mediawiki/skin s/panorama /death_val ley_flower s_panorama .jpg
TO
death_valley_flowers_panor ama.jpg'
Any help appreciated.
Thank you.
I have a php file that has the following statement:
<img src=" <?php echo 'http://localhost/mediawiki/skins/panorama/death_valley_flowers_panorama.jpg' ?>" style="width: 928px; height: 147px; border: 1 none; filter: alpha(opacity=20); -moz-opacity: 0; opacity: 0;" id="blendimage""/>
When the page loads, I can see the image 'death_valley_flowers_pano
The folder where this image is, is in:
C:\wamp\www\mediawiki\skin
and there are many images in here.
A variable called $init_pic holds the full path to the location of the panorama folder, and randomly returns an image from that folder.
But if I define img src like the following.....
<img src=" <?php echo 'http://localhost/mediawiki/skins/panorama/' . $init_pic ?>
What $init_pic expands out to is:
C:/wamp/www/mediawiki/skin
That is the FULL PATH to the random image.
So I end up with img src expanding out to be:
http://localhost/mediawiki/skins/panorama/C:/wamp/www/mediawiki/skins/panorama/death_valley_flowers_panorama.jpg
which is wrong...it cant find that.
If I place in a hardcoded image path as follows:
<img src=" <?php echo 'http://localhost/mediawiki/skins/panorama/' . 'death_valley_flowers_pano
This loads fine.
But I need the $init_pic variable in there so that the image can change.
The only problem is that with $init_pic in there, I get the following:
http://localhost/mediawiki/skins/panorama/C:/wamp/www/mediawiki/skins/panorama/death_valley_flowers_panorama.jpg
I need somehow to make img src look like the following:
<img src=" <?php echo 'http://localhost/mediawiki/skins/panorama/' . 'death_valley_flowers_pano
but where 'death_valley_flowers_pano
$int_pic returns the full path to the image.
Is there any way to first return that full path, then cut off everything from the front, to just leave the resulting image name?
So, in other words, is there a function or something that can do the following....
<img src=" <?php echo 'http://localhost/mediawiki/skins/panorama/' . '$int_pic?>
Then before img src is set to this, as this will be wrong....
Trim off the expanded $int_pic variable
from
C:/wamp/www/mediawiki/skin
TO
death_valley_flowers_panor
Any help appreciated.
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much for your help mate.
I tried this and it worked but was a bit hit and miss. Sometimes it would not select an image from the folder, so the page when loaded, had no image. Other times it did.
gl....what I really need is to use the following....
The following php function retrieves the randomized images always:
==========================
<?php
global $IP;
$images = glob(dirname(__FILE__).'/p
foreach ($images AS $k=>$v) $images[$k] = ereg_replace("^$IP","/",$v
$indx = 0;
$init_pic = $images[array_rand($images
foreach($images AS $pic)
{
echo "galleryarray[$indx]='$pic
";
$indx++;
}
?>
==========================
In the above, the $init_pic holds a randomly selected image name from
C:\wamp\www\mediawiki\skin
So I need to use:
<img src=" <?php echo 'http://localhost/mediawiki/skins/panorama/' . '$int_pic?>
But with $int_pic not the full path, but just image.jpg, or whatever image it holds at any time.