By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,456 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,456 IT Pros & Developers. It's quick & easy.

Include problem

P: n/a
Hi, I'm currently writing website using php. My problem is, when I do:

include("../../library/file.php"); // this is from e.g
/level1/level2/something.php

it works. However, when I use:

include("../../../library/file.php"); // and this one from
/level1/level2/level3/something.php

it doesn't work. So, does the include statement in php only cover 2
upwards directories? Is there anyway around this?
Thanks.
Nic
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Kupo wrote:
My problem is, when I do:

include("../../library/file.php");
// this is from e.g /level1/level2/something.php

it works. However, when I use:

include("../../../library/file.php");
// and this one from /level1/level2/level3/something.php

it doesn't work.
/How/ does it not work?

it includes a different file? :)
it gives a error message? ==> try error_reporting(E_ALL);
what is the error message?
it just ignores the include()?
So, does the include statement in php only cover 2
upwards directories?
No.
Is there anyway around this?
Maybe if you specify the path from the root

include '/library/file.php';

no matter how deep you are in the directory structure.
Thanks.


It works for me:

$ cat /home/pedro/src/php/test.php
#!/usr/bin/php
<?php
error_reporting(E_ALL);
include 'inc.php';
include '../php/inc.php';
include '../../src/php/inc.php';
include '../../../pedro/src/php/inc.php';
include '../../../../home/pedro/src/php/inc.php';
include '../../../../../../../../../home/pedro/src/php/inc.php';
echo "Done!\n";
?>

$ cat /home/pedro/src/php/inc.php
<?php
echo "inside included file\n";
?>

$ cd /home/pedro/src/php
$ ./test.php
inside included file
inside included file
inside included file
inside included file
inside included file
inside included file
Done!

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

P: n/a

<Kupo> wrote in message news:qt********************************@4ax.com...
Hi, I'm currently writing website using php. My problem is, when I do:

include("../../library/file.php"); // this is from e.g
/level1/level2/something.php

it works. However, when I use:

include("../../../library/file.php"); // and this one from
/level1/level2/level3/something.php

it doesn't work. So, does the include statement in php only cover 2
upwards directories? Is there anyway around this?
Thanks.


Have a play with getcwd() to find out where you are, and work it from there.
Then you have to worry about permissions, chroot jails, etc.

Garp
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.