Re: getting absolute directory path?



On 24 Apr, 16:32, lawp...@xxxxxxxxx wrote:

First of all, I have a website under /home/user/www/. The index.php
and all the other website pages are under /home/user/www/. For
functions that are used in multiple files, I have php files under /
home/user/www/functions/. These files simply have

So, in index.php and other files, I have
<?php
include("./functions/function.create_html_page.inc");
include("./functions/function.create_pdf.inc");
....
?>

And then function files, such as function.create_html_page.inc
<?php
function create_html_page( $arg1, $arg2 ) {
...}

?>

So, my php pages have relative references to the function files, i.e.
"./functions/".

This works okay, but when I want to include a function in a function
file, I have to change the relative path. So, instead of
include("./functions/function.create_pdf.inc");
I should have
include("./function.create_pdf.inc");

Ideally I would like to figure out the absolute path name, so that I
don't have to change the relative path names depending on whether the
file is in the root directory or the functions directory, or any other
directory for that matter.


No.

Put all your include files in a directory referenced by the ini
include_path (or a specific sub-directory thereof). Then its a no
brainer to always reference the right file regardless of where it is
included from.

My website is designed so that pages in subdirectories are never
served; the user is always navigating in the root directory. So, even
if a function in the functions subdirectory are called, the original
executing script was in the root.

Setting yourself such a constraint is a very bad idea - its
ridiculously restrictive and encourages bad habits (dumping too many
files into one folder).

C.
.



Relevant Pages

  • Re: =& when creating new object
    ... $reference point to the same memory location. ... Please read the chapter called "references are not pointers" in the ... should not consider it an address in PHP. ...
    (comp.lang.php)
  • Re: PHP5 and class inheritance question
    ... handle pointing to a memory address where information is stored, this php ... handle points to a symbol table entry where information is stored. ... A pointer contains a memory address, ... references behave differently (which BTW is explicitly mentioned in the ...
    (comp.lang.php)
  • Re: [PHP] Odd PHP memory issue
    ... This MAY be fixed in current PHP -- I just know it was once an issue. ... references go out of scope or are unset. ... Forget "go out of scope" as a solution to memory management. ...
    (php.general)
  • Re: =& when creating new object
    ... & means 'a reference to the memory location where the value is stored'. ... That was probably the single most unique new concept (pointers and address-of) I had conquer when I learned C, coming from a Fortran background as I did. ... Please read the chapter called "references are not pointers" in the manual. ... But you should not consider it an address in PHP. ...
    (comp.lang.php)
  • getting absolute directory path?
    ... functions that are used in multiple files, I have php files under / ... I have to change the relative path. ... the user is always navigating in the root directory. ... OLDPWD looks like it would work, but I couldn't find it documented ...
    (comp.lang.php)