Page 1 of 1

relational links and using include files ??

Posted: Tue Oct 10, 2006 5:36 pm
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]

Posted: Tue Oct 10, 2006 5:45 pm
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.

Posted: Tue Oct 10, 2006 5:48 pm
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";

Posted: Tue Oct 10, 2006 6:28 pm
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.

Posted: Tue Oct 10, 2006 8:07 pm
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";