Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Error including a file which includes another file.
Old 01-23-2010, 05:09 PM Error including a file which includes another file.
Novice Talker

Posts: 5
Trades: 0
I think the problem is that the inluder is including a file using a path relative to it's location, but the included is written to include relative to it's location, but php is including relative to the includers location. Gah, It's hard for me to explain.

Here, extract this(attachment) to a local server which supports php. Then visit the page problem1/c/d/d.php
Attached Files
File Type: zip problem1.zip (988 Bytes, 0 views)
jeremywilms is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-23-2010, 05:59 PM Re: Error including a file which includes another file.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
use

PHP Code:
<?php include($_SERVER['DOCUMENT_ROOT']."/a/b/c/d/filename.php")?>
To reference it as a root relative path.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-23-2010, 06:35 PM Re: Error including a file which includes another file.
Novice Talker

Posts: 5
Trades: 0
Thank you very much chrishirst !
jeremywilms is offline
Reply With Quote
View Public Profile
 
Old 01-23-2010, 09:30 PM Re: Error including a file which includes another file.
Novice Talker

Posts: 5
Trades: 0
Is there anyway to include using a relative path though? If I move files around, I don't want everything to break.

I know I can include relative to the current location via ../, but as you can see, that isn't working with my problem.(reread first post for details on problem).

in other words:
Is there any way the includee can acquire it's location, which isn't effected by the includers location?

Last edited by jeremywilms; 01-23-2010 at 09:48 PM..
jeremywilms is offline
Reply With Quote
View Public Profile
 
Old 01-23-2010, 10:03 PM Re: Error including a file which includes another file.
Novice Talker

Posts: 5
Trades: 0
AHA!

echo dirname(__FILE__);
will return the directory the include file is located, which won't be effected by the includers location.

That's much better then using an absolute path. Thanks for your reply.
jeremywilms is offline
Reply With Quote
View Public Profile
 
Old 01-24-2010, 07:46 AM Re: Error including a file which includes another file.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
A root relative reference is always in the same place regardless of where the including page is in the site folder hierarchy.

Using the ../ syntax would require an extra ../ to be added for each folder the including page was away from the root.

If you need find the path to the current file you can use use
PHP Code:
<?php echo(str_replace('index.php','',$_SERVER['SCRIPT_NAME'])); ?>
// replace index.php with the page name
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Error including a file which includes another file.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.38491 seconds with 13 queries