Page 1 of 2
including dynamic pages
Posted: Thu Sep 16, 2004 5:23 pm
by bradles
Hi All,
I have set up a page that reads a thumbnails directory and then displays the thumbnails on the page. This script reads the /thumbnails directory.
If I try to include this file on another page somewhere else it errors out because there isn't a thumbnail folder in the directory that runs the parent script.
What is the best method for doing something like this?
Brad.
Posted: Thu Sep 16, 2004 5:26 pm
by John Cartwright
umm?
include '../thumbnails.php';
??
Posted: Thu Sep 16, 2004 5:44 pm
by bradles
Hi Phenom.
My problem occurs when I have the thumbnails.php in different folder to the main script that it is included on.
Example:
index.php is in the www directory.
thumbnails.php is in the www/clients/smith directory.
There is no /thumbnails folder in the www directory so when the index.php script runs and has the thumbnails.php script included on it, the thumbnails.php searches the www directory for a thumbnails folder.
Does that make sense?
Brad.
Posted: Thu Sep 16, 2004 5:45 pm
by feyd
adjust the include path, or use the document root: $_SERVER['DOCUMENT_ROOT']
Posted: Thu Sep 16, 2004 6:17 pm
by John Cartwright
Yes, adjust the path is what I meant for you to get out of my post..

Posted: Thu Sep 16, 2004 6:19 pm
by bradles
OK.
It is sort of working. The only problem now is that the thumbnails.php has an included style which doesn't work.
<link href="../../styles/image_gallery_styles.css" rel="stylesheet" type="text/css" />
If the thumbnails.php is included on the index.php it searches back 2 directories from the folder that the index.php is in...which isn't possible.
Do you know how to rectify this?
Posted: Thu Sep 16, 2004 6:21 pm
by feyd
use an absolute path.
Posted: Thu Sep 16, 2004 6:25 pm
by bradles
what about on a testing server? Is there a way I can use an absolute path and still be able to test it on the testing server before uploading.
Or do I have to change it to the correct absolute path after uploading?
Brad.
Posted: Thu Sep 16, 2004 6:28 pm
by feyd
you can set it up to automatically switch when you move to the live server using $_SERVER['HTTP_HOST'] or other environment information...
Code: Select all
<link href="/web/viewable/path/from/document/root/whatever.css" rel="stylesheet" type="text/css" />
Posted: Thu Sep 16, 2004 6:41 pm
by bradles
feyd wrote:you can set it up to automatically switch when you move to the live server using $_SERVER['HTTP_HOST'] or other environment information...
Code: Select all
<link href="/web/viewable/path/from/document/root/whatever.css" rel="stylesheet" type="text/css" />
Do you know how I do this? I thought you might just put something like the following as the styles link but that doesn't work.
Code: Select all
<link href="<?$_SERVERї'HTTP_HOST']?>/styles/image_gallery_styles.css" rel="stylesheet" type="text/css" />
Posted: Thu Sep 16, 2004 6:49 pm
by feyd
something more like:
Code: Select all
$site_root = $_SERVERї'HTTP_HOST'] == 'localhost' ? '/devroot' : '/liveroot';
Code: Select all
<link href="<?php echo $site_root ?>/web/viewable/path/from/document/root/whatever.css" rel="stylesheet" type="text/css" />
although I'd suggest using a template system/engine set up.
Posted: Thu Sep 16, 2004 7:07 pm
by bradles
feyd wrote:something more like:
Code: Select all
$site_root = $_SERVERї'HTTP_HOST'] == 'localhost' ? '/devroot' : '/liveroot';
I understand the include part of your suggestion feyd. What is the above line actually doing? The "==", ? and : are throwing me...but I'd really appreciate you helping me understand.
Thanks.
Posted: Thu Sep 16, 2004 7:13 pm
by feyd
expression1 == expression2
returns true if expression1 is equal to expression2
expression1 ? expression2 : expression3
evaluates expression1, if it returns true, expression2 is returned; otherwise, expression3 is returned.
Posted: Thu Sep 16, 2004 7:24 pm
by bradles
feyd wrote:expression1 == expression2
returns true if expression1 is equal to expression2
expression1 ? expression2 : expression3
evaluates expression1, if it returns true, expression2 is returned; otherwise, expression3 is returned.
Uhm....can I kiss you?

(just kidding)
Thank you so much. I implemented the following:
Code: Select all
<? $site_root = $_SERVER['HTTP_HOST'] == 'localhost' ? '/TestServer/RootFolder/styles' : '/styles'; ?>
<link href="<? echo $site_root ?>/image_gallery_styles.css" rel="stylesheet" type="text/css" />
My problems are solved.
Thankyou so much for your help with this feyd. Your patience is so much appreciated.
Brad.
Posted: Thu Sep 16, 2004 7:41 pm
by dethron
And let me do some little change

Use
Code: Select all
<link href="<?=$site_root ?>/image_gallery_styles.css" rel="stylesheet" type="text/css" />
Instead
Code: Select all
<link href="<? echo $site_root ?>/image_gallery_styles.css" rel="stylesheet" type="text/css" />
make use of the <?=$somestringvar?>