relational links and using include files ??

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

Post Reply
xyloft
Forum Newbie
Posts: 2
Joined: Tue Oct 10, 2006 5:24 pm

relational links and using include files ??

Post by xyloft »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i'm fairly sure i have seen how to do this, but for the life of me i can't find the example.  

i've googled for a while, and read some stuff on php.net, but no luck.  so basically here's what i want to do.  hopefully someone knows it simply off the top of their head.  i feel like this should be a super basic question, but couldnt find it anywhere. 


so my web directory looks similar to this:

http://www.webroot.com/pictures/*.gif

http://www.webroot.com/application/summary.php

http://www.webroot.com/application/deta ... equery.php

for clarity here are some dummy pages (not syntactically correct):



this is the summary page:\

Code: Select all

<? disply msg variable  ?>

<form action='./details/databasequery.php'> 
     <input  type=image src="../pictures/click.gif" alt="" width="75" height="1">
</form>

this is the database.php page

Code: Select all

<?
   run query;
   set msg variable;
   include "../summary.php";
?>


the problem is once i include the summary page all of the links are now broken (because i am working in "/application/details" ), so i need a way to set the working directory back to "/application"

thanks in advance. i hope i was clear enough?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

URLs can be set to use /applications, /pictures and so forth. File references will normally stay at the working directory of the initial script.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

relatives paths in the local filesystem are always relative to the current working directory (cwd). As feyd said usually the cwd is set to the path of the initial php script. include() does not change the cwd.
You can display the cwd for debugging purposes with

Code: Select all

<?php echo '<div>cwd: ', getcwd(), "</div>\n";
xyloft
Forum Newbie
Posts: 2
Joined: Tue Oct 10, 2006 5:24 pm

Post by xyloft »

thanks guys.

so there is no way to change the current working directory after i call the include? the only work around is to change how i write my relative paths?

i guess my include in these examples is more like an HTTP-Refresh. i do not want to be in the calling script, but want to be in the included script only.
chakhar86
Forum Commoner
Posts: 45
Joined: Mon Jun 05, 2006 1:36 am
Contact:

Post by chakhar86 »

Actually there's a way to change the working directory (but I forgot the function).

But it's better to use a absolute path to reference to other directory.
example:
you have this structure:

myweb.com/interface/log/login.php
myweb.com/lib/log/login_handler.php
myweb.com/lib/log/auth.php
myweb.com/dynamic/log/log.js

this is the login.php file's content:

Code: Select all

<?php
   $root_path = "./../../";
   include ($root_path."lib/log/login_handler.php");
   include ($root_path."lib/log/auth.php");
?>
<script language="javascript" src="./../../dynamic/log/log.js"></script>

and so on
So, you have a global variable "$root_path" which can be used in included code so you can reference to any file, just write $root_path."full_path";
Post Reply