PHP path reference for ../

What determines how PHP evaluates things like

                               include( ../file.html);

My experience is that this is normally evaluated with respect to the location of the script that contains the line but I've come across a situation where it's being evaluated with respect to an absolute address.  How do you tell PHP to evaluate these with respect to some absolute address?

Thanks for any info.

Steve
stevaAsked:
Who is Participating?
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
'../' means the directory above the current directory.  However, when you 'include', the reference is the location of the main file.  '/' (just a slash) is the root of your web directory.  So "/images/blank.gif" means to find "blank.gif" in the 'images' directory which is found in your web root.

Note that if you use include ("http://yourwebsite.com/file.php"), you will get the results of that PHP file, not it's contents or code.
0
 
Mark BradyConnect With a Mentor Principal Data EngineerCommented:
You can set the include path either in the php.ini file or directly from your script. Here's a quick example of setting it inside your script.

$path = '/usr/lib/pear';

set_include_path(get_include_path() . PATH_SEPARATOR . $path);

I usually create a config file which sets all that stuff and things like constants etc... then include that file with all others. As Dave stated above, it is relative to your document.
For security reasons "include" or "require" statements only work with local files (on the same server as your main script).
0
 
stevaAuthor Commented:
Thanks.  

I think my issues are with the CodeIgniter framework I'm working in.  I'm trying to make sense of this from a PHP view but CodeIgniter seems to be doing something above PHP on its own.  

A file has

require('../config.php');

and if I insert code in that file to display the results of get_include_path() I see:

                           include path=.:/usr/share/php:/usr/share/pear

But config.php is actually being pulled relative to the top codeigniter directory, i.e., up one from ci and down to the config.php there.

Thanks for your input, though.

Steve
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Dave BaldwinFixer of ProblemsCommented:
That's from 'php.ini'.  'include path' is where PHP looks if the file is Not found in the specified place.
http://php.net/manual/en/function.include.php
0
 
stevaAuthor Commented:
But in my case PHP is finding a way to resolve the ../ without using the current directory or what's in the include_path. The full directory involved is
path
When the include(../config.php) in uploader_settings.php is evaluated, the circled config.php comes in.  Somehow CodeIgniter has inserted its own path so that the ci folder - the top of the CodeIgniter stuff -  is the reference for evaluating ../.

This will probably become clearer after studying more about CodeIgniter.  I'm just surprised that it can do anything that overrides the basic PHP path evaluation.
0
 
Dave BaldwinFixer of ProblemsCommented:
"PHP path evaluation"??  PHP uses the path structures, directories and files, of the underlying operating system.

In addition, " include path=.:/usr/share/php:/usr/share/pear" are places that you can't put any files normally (unless you get 'root' access on the server).

If you want the 'config.php' in the same directory, that what you put:  include(config.php);
0
 
stevaAuthor Commented:
Yeah.  I don't know.  Basically I don't understand how the include(../config.php) in uploader_settings.php above loaded the config.php circled in the figure above.  I need to go deeper into CodeIgniter to understand what going on..

Cheers
0
 
Dave BaldwinFixer of ProblemsCommented:
Are you seeing this on your own computer or on your web hosting?
0
 
stevaAuthor Commented:
Web hosting,  on a Linux/Apache server.  But it is doing what it should.  It needs to load that particular config file that I've circled.  That's where all the config options are for the upload operation it's doing.  I just don't know how include(../config.php) from uploader_settings.php accomplishes that.  

Have you done anything with CodeIgniter, or other PHP frameworks?
0
 
Dave BaldwinFixer of ProblemsCommented:
I generally avoid frameworks like the plague.  It's difficult enough without some program pretending it knows better than you.  While I'm sure they are useful for the things they are intended for, I have no idea what that might be.

I especially would not run any IDEs that provide their own 'web server' because your actual web hosting is always going to be somewhat different.  I have at least 3 versions of Apache and 3 versions of IIS that I have dealt with.  Add to that 3 or 4 versions of PHP and MySQL and MS SQL,  I can't have my development situation limited to what only one IDE can provide.
0
 
stevaAuthor Commented:
I generally avoid frameworks like the plague.  It's difficult enough without some program pretending it knows better than you.  While I'm sure they are useful for the things they are intended for, I have no idea what that might be.
That was pretty much my opinion, until some code was dropped in my lap that I had to understand and it used CodeIgniter, so I was dragged kicking and screaming to it.

But it's not bad! Basically you get "professional" code that does the things that are typically wily in PHP (database, security, login, sessions, file uploads, image manipulation . . .)  and your finished pages aren't a godawful  mixture of PHP, HTML and database code.   If you have 32 minutes you might find this video - "CodeIgniter from Scratch" -  interesting: http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-day-1/
0
 
Dave BaldwinFixer of ProblemsCommented:
But I almost specialize in fixing "godawful mixtures of PHP, HTML and database code".  That's where I make my money on the web.  I have 'undone' Dreamweaver, Adobe Go Live, Microsoft Publisher and Front Page, and Apple's iWeb to make them work.  There are several that I won't touch such as Smarty templates, Xoops, and NetObjects Fusion.  While they may be well organized, they are complicated beasts and not worth my effort to understand and fix.
0
 
stevaAuthor Commented:
OK, then it's probably not for you.   I make my money on the web building things for people, and to me it looks like it might replace the hammer in my toolbox with a nail gun - so I'm interested.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.