470,815 Members | 1,329 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Include problem

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
2 2209
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

<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.

Similar topics

11 posts views Thread by Yannick Turgeon | last post: by
43 posts views Thread by steve | last post: by
6 posts views Thread by alan | last post: by
6 posts views Thread by atv | last post: by
60 posts views Thread by Derrick Coetzee | last post: by
5 posts views Thread by David Mathog | last post: by
6 posts views Thread by tshad | last post: by
5 posts views Thread by Tio | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.