You are here: Re: Using Relative Paths With include() « All PHP « IT news, forums, messages
Re: Using Relative Paths With include()

Posted by Etienne Marais on 11/16/05 15:46

> Is there anyway to get the name and directory of the currently executing
> file regardless of whether or not it has been included in another?
> Because if you have multiple files including currentfile.php, you're
> going to need to tweak your include() statement for each one unless there
> is some way to work around that.

For larger projets I start with index.php in the topmost directory, and
have a directory structure of the like:

../include
../include/extension1/
../include/extension2/
../include/extra_lib1/

../dta
../dta/excel_data.xls
../dta/xml_data.xls

index.php simply sets the include path:

ini_set("include_path",get_include_path().":.:./include/:./include/extension1:./inc.....");

If you use some code over and over, say include/extra_lib1,
move it out of the project tree up into the document root
and edit php.ini to point to that directory.

Since I have been coding OO (before PHP 5) entry into the
system is ALLWAYS via index.php so the problem you mention
is not applicable to me. Even without OO you can branch
your code from index.php so that you don't load sub_program_part1a.php
into the url, but include/require as needed, so the paths are
allways set and you just include what you need without including
the directory in the include/require statement.

If you need to find info about the main running script, check out:

$_SERVER["REQUEST_URI"]
$_SERVER["SCRIPT_NAME"]
$_SERVER["PHP_SELF"]

to find info about the current working directory (the directory relative
from where anything needs to be included, regardless the running script)
try)

$cwd=`pwd`; // Linux
$cwd=exec("dir"); // or something like this for windows.

I'm shure there must be something to find information about the
'running sub script' but I don't know what it is :(

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация