Connecting Tech Pros Worldwide Forums | Help | Site Map

Include problem

Kupo
Guest
 
Posts: n/a
#1: Jul 17 '05
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

Pedro Graca
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Include problem


Kupo wrote:[color=blue]
> 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.[/color]

/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()?
[color=blue]
> So, does the include statement in php only cover 2
> upwards directories?[/color]

No.
[color=blue]
> Is there anyway around this?[/color]

Maybe if you specify the path from the root

include '/library/file.php';

no matter how deep you are in the directory structure.
[color=blue]
> Thanks.[/color]

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 :
Garp
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Include problem



<Kupo> wrote in message news:qt1970hgm5cfd2aktajgvht8vp8ndidct0@4ax.com...[color=blue]
> 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.[/color]

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


Closed Thread


Similar PHP bytes