Random Image issue with path to images
Random Image issue with path to images
So I have code set up to grab random images as such:
<img src="<?php $_GET['folder']='../images/subpages/landscape/'; include 'includesPHP/random.php'; ?> width="350" height="150" alt="Random Image" /></div>
This issue is that the above code in itself is another include file on our site so that the path of the images will change depending on how deep inthe site you are. What I need to do is set up the path of the images to be set up like a virtual directory like we did for the random.php script itslef.
What is the best waht to do that? I tried just /images to be relative to the server root but no dice.
<img src="<?php $_GET['folder']='../images/subpages/landscape/'; include 'includesPHP/random.php'; ?> width="350" height="150" alt="Random Image" /></div>
This issue is that the above code in itself is another include file on our site so that the path of the images will change depending on how deep inthe site you are. What I need to do is set up the path of the images to be set up like a virtual directory like we did for the random.php script itslef.
What is the best waht to do that? I tried just /images to be relative to the server root but no dice.
I would love to do that - the absolute path would fix this.
But when i try
<img src="<?php $_GET['folder']='/images/subpages/landscape/'; include 'includesPHP/random.php'; ?> width="350" height="150" alt="Random Image" />
for the GET folder part - it cant find the images even though that path is correct for a root relative path.
I cant use ../../ because while that may work for one page, it will not work on, say, a page that is one level deeper.. I would have to use ../../../ .
Because the image code is an include file itself I can drop it in many pages easily but need to find a way to have a path that works at any level, hence the server or site relative path using a / (or something similar that will work).
I must be coding something wrong cause this must work this way somehow, no?
Any ideas?
But when i try
<img src="<?php $_GET['folder']='/images/subpages/landscape/'; include 'includesPHP/random.php'; ?> width="350" height="150" alt="Random Image" />
for the GET folder part - it cant find the images even though that path is correct for a root relative path.
I cant use ../../ because while that may work for one page, it will not work on, say, a page that is one level deeper.. I would have to use ../../../ .
Because the image code is an include file itself I can drop it in many pages easily but need to find a way to have a path that works at any level, hence the server or site relative path using a / (or something similar that will work).
I must be coding something wrong cause this must work this way somehow, no?
Any ideas?
I meant an absolute path like:WebPhenom wrote:<img src="<?php $_GET['folder']='/images/subpages/landscape/'; include 'includesPHP/random.php'; ?> width="350" height="150" alt="Random Image" />
Code: Select all
<img src="<?php $_GET['folder']='http://www.yoursite.com/images/subpages/landscape/'; include 'http://www.yoursite.com/includesPHP/random.php'; ?> width="350" height="150" alt="Random Image" />
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
You are right, it should work with absolute paths. I may be stupid to ask, but you are certain the paths you entered are valid?
Could you post the php files (the random.php script and one page from which you call it) somewhere in a zip file so i can take a look at the code? Not sure when I have time to look at it, but when it is not available, i am sure i can not help you any more.
Regards,
Henrie
Could you post the php files (the random.php script and one page from which you call it) somewhere in a zip file so i can take a look at the code? Not sure when I have time to look at it, but when it is not available, i am sure i can not help you any more.
Regards,
Henrie
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
I looked at it. I never used the random image script myself.
Could you add following as first line to webservices.php, this will display errors if present.
Also please create a file includetest.php with following content:
And add following to webservices.php (change paths to what you think are the correct relative and absolute paths to the includetest.php file).
Please let me know if you get any errors.
On my own local running server I get an error with the full url, my php default setting is to not accept URL file-access for php include function.
Greetings,
Henrie
Could you add following as first line to webservices.php, this will display errors if present.
Code: Select all
<?php ini_set('display_errors', 1); ?>
Code: Select all
<?php echo 'This is content of includetest.php file displayed'; ?>
Code: Select all
<?php
echo '<hr>relative link to includetest.php (result on next line):<br>';
include '../includetest.php';
echo '<hr>absolute (full url) link to includetest.php (result on next line):<br>';
include 'http://127.0.0.1/includetest.php';
?>
On my own local running server I get an error with the full url, my php default setting is to not accept URL file-access for php include function.
Greetings,
Henrie
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
i did get an error for the absolute include.
IN my ini file i have include_path='.;c:\inetpub\wwwroot' this allows me to access includes like this
but i cant get the the server root / which is where i placed the includetest.php file.
Is the issue I need to set up my PHP enviroment to access the server root / and if so, how?
Code: Select all
<?php
echo '<hr>relative link to includetest.php (result on next line):<br>';
include '../../includetest.php';
echo '<hr>absolute (full url) link to includetest.php (result on next line):<br>';
include '/includetest.php';
?>
Warning: include(/includetest.php) [function.include]: failed to open stream: No such file or directory in C:\Inetpub\wwwroot\includesPHP\headers\webservices.php on line 15
Warning: include() [function.include]: Failed opening '/includetest.php' for inclusion (include_path='.;c:\inetpub\wwwroot') in C:\Inetpub\wwwroot\includesPHP\headers\webservices.php on line 15
Code: Select all
include 'includes/test.php';
Is the issue I need to set up my PHP enviroment to access the server root / and if so, how?
The error mesasge you get says it all: "failed to open stream: No such file or directory"
It means your folder settings are wrong. Try using he FULL paths in includes, I mean like include 'C:\Inetpub\wwwroot\includesPHP\headers\script.php';
It means your folder settings are wrong. Try using he FULL paths in includes, I mean like include 'C:\Inetpub\wwwroot\includesPHP\headers\script.php';
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
I am sorry, my knowledge of configuring php on the server is not so good that i can help you with this.
Seems your knowledge is already bigger than mine
Greetings,
Henrie
Edit: lol, it seems Klemen and I were writing at the same time. He just pushed Submit a little earlier than me.
Seems your knowledge is already bigger than mine

Greetings,
Henrie
Edit: lol, it seems Klemen and I were writing at the same time. He just pushed Submit a little earlier than me.
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
yes i can get the include working using that or server document root :
but i still am not able to get the random image to accept an absolute page for the get folder. Ieven tried:
This pulls in the include file but I am getting a broken image now as the image path now:
Doing it as just /images/subpages/landscape/ gives me the NO IMAGE icon.
I tried every way i cant think of to get it to work with an absolute or site/root relative path and no dice. It seems to only with with page relative links like ../../ etc.
I am just trying to get the override working because our images are in many places and I want to be able to grab them from the SRC i specify on each page. This code seemed the perfect solution if only we could get the absolute path working for GET Folder variable.
Code: Select all
include ($_SERVER['DOCUMENT_ROOT'].'/includetest.php');
Code: Select all
<?php $_GET['folder']= ($_SERVER['DOCUMENT_ROOT'] . "/images/subpages/landscape/"); include ($_SERVER['DOCUMENT_ROOT'] . "/includesPHP/randomimage.php"); ?>"
Code: Select all
<img src="c:\inetpub\wwwroot/images/subpages/landscape/image098.jpg"
I tried every way i cant think of to get it to work with an absolute or site/root relative path and no dice. It seems to only with with page relative links like ../../ etc.
I am just trying to get the override working because our images are in many places and I want to be able to grab them from the SRC i specify on each page. This code seemed the perfect solution if only we could get the absolute path working for GET Folder variable.
the <img src="c:\inetpub\wwwroot/images/subpages/landscape/image098.jpg"> src path must be accessible from the webbrowser. This usually means it should be a path like "http://www.youriste.com/images/subpages ... age098.jpg"
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.