why can't i use root paths in my includes?
Moderator: General Moderators
why can't i use root paths in my includes?
I'm new to PHP. I've been developing in ASP with IIS for my server environment and am trying to make a transition to the whole PHP/Apache/MySQL thing. I want to love PHP, but I've had so many frustrations that have just <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> me off that it's becoming a burden. Please help me out with this dilemma I have. Why can't I use an absolute path to call my PHP include? For instance, when I'm calling my include with a relative path like so:
<?php include('../includes/myinclude.php'); ?>
it works fine, but when I try to call it like this:
<?php include('/includes/myinclude.php'); ?>
I get an Warning: Failed opeining '/includes/myinclude.php' for includsion blah blah blah. PLEASE!!! Help me out...
<?php include('../includes/myinclude.php'); ?>
it works fine, but when I try to call it like this:
<?php include('/includes/myinclude.php'); ?>
I get an Warning: Failed opeining '/includes/myinclude.php' for includsion blah blah blah. PLEASE!!! Help me out...
I've tried everything listed in this thread and I'm still not able to include a file. I am renting server space and it appears that I can't access the php.ini file to update my include paths. I also CHMOD 'd the file calling the script.
I've tried it these ways:
I always get this response. (I took out the full paths)
I've tried it these ways:
Code: Select all
<?php include ("/test/tables.php"); ?>
<?php include ("test/tables.php"); ?>
<?php include ('test/tables.php'); ?>
<?php include (' //used full path to /test/tables.php'); ?>P.S. I know it can be done because I'm running PHPNuke on the site and it is making the same calls. I'm missing something really simple, any help would be much appreciated.Warning: Failed opening '/test/tables.php' for inclusion (include_path='.:/usr/local/share/pear:/usr/local/lib/php') in /test/index.php on line 5
first, a question: why does it bother you to put the ../ in front of the path?
now, a response: here's what happens, to the best of my knowledge, when you call any of the include* or require* functions. The current working directory of the PHP process is where the script is. For our example, we'll assume that it's '/var/www/php/project/php_script.php'. In a unix system, '/' is similar to the 'c:'' directory in windows; it's the base of the whole filesystem. If you write: PHP looks in the directory '/includes/script.php', which (probably) doesn't exist. (at a command prompt, try 'ls /'). If it doesn't exist, PHP returns the error you've described.
Now, if you write PHP sees a relative file path. That is, the '..' means 'up one directory', so PHP looks up one directory (in '/var/www/php/') for a directory named 'includes'. If it exists, it then looks for a file called 'script.php'. If one of those doesn't exist, PHP again returns the error you've described. If the both exist, PHP loads the file.
For one final example, if you write PHP sees another relative path, this time less specific than the first two. The first thing it does is check the current directory for a directory named "includes" with a file named "script.php" inside it. Second, it goes through all the directories in the 'include_path' variable in your php.ini, looking for an "includes" directory with a file "script.php" inside it. Again, if it can't find it, it returns an error, else it loads the file.
Hope this helps you understand what's going on.
now, a response: here's what happens, to the best of my knowledge, when you call any of the include* or require* functions. The current working directory of the PHP process is where the script is. For our example, we'll assume that it's '/var/www/php/project/php_script.php'. In a unix system, '/' is similar to the 'c:'' directory in windows; it's the base of the whole filesystem. If you write:
Code: Select all
include('/includes/script.php')Now, if you write
Code: Select all
include('../includes/script.php')For one final example, if you write
Code: Select all
include('includes/script.php')Hope this helps you understand what's going on.
I guess there is a misunderstanding
It wouldn't bother me to include a , but that doesn't work right now for some reason. I included all the different ways that i have tried to get the file to get included and none of them worked.
I even used the absolute path from root (ie)and it didn't work.
I know just about enough to hurt myself,lol, but i have run Linux for 4 years and have installed lots of stuff in unix type boxes but this one is bugging me
Code: Select all
<?php
../include/blah.php
?>I even used the absolute path from root (ie
Code: Select all
<?php
/home/name/www/html/src/whatever.file
?>I know just about enough to hurt myself,lol, but i have run Linux for 4 years and have installed lots of stuff in unix type boxes but this one is bugging me
NM, I figured it out. I'm not sure why but if I do it this way is works.
Thanks for the response 
Code: Select all
<?php
include<'./includes/tables.php');
?>