[SOLVED] including dynamic pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

including dynamic pages

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

umm?

include '../thumbnails.php';

??
bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

adjust the include path, or use the document root: $_SERVER['DOCUMENT_ROOT']
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Yes, adjust the path is what I meant for you to get out of my post.. :P
bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use an absolute path.
bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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" />
bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

Post 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&#1111;'HTTP_HOST']?>/styles/image_gallery_styles.css" rel="stylesheet" type="text/css" />
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

something more like:

Code: Select all

$site_root = $_SERVER&#1111;'HTTP_HOST'] == 'localhost' ? '/devroot' : '/liveroot';

Code: Select all

&lt;link href="&lt;?php echo $site_root ?&gt;/web/viewable/path/from/document/root/whatever.css" rel="stylesheet" type="text/css" /&gt;
although I'd suggest using a template system/engine set up.
bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

Post by bradles »

feyd wrote:something more like:

Code: Select all

$site_root = $_SERVER&#1111;'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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

Post 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? 8) (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.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post 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?>
Post Reply