Help - Search - Members - Calendar
Full Version: Root Directory In Php Include
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
akpokemon
Hey!

Alrighty...so I'm using the code:
CODE
<?php include('../html_document.txt'); ?>

to include my HTML coding in the PHP pages on my site. It works beautifully for all php documents 1 folder from the root directory. I use the
CODE
../
characters before the file name for the php documents within the non-root-directory folders, and it works great.

But with php documents 2 folders from the root directory, the
CODE
../
characters before the file name don't work anymore and don't refer back to the root directory for some reason. I always thought the
CODE
..
meant to refer to the root directory, but of course, I always used HTML instead of PHP before moving to this host, so I'm not sure. tongue.gif

Could someone please help me? I'll tell you the exact error code I get once the UUUQ server is back up.

Thanks! smile.gif
akpokemon
Okay here's the error I get:

CODE
[b]Warning:[/b] include() [function.include]: Unable to access ../top.txt in [b]/www/uuuq.com/a/k/p/akpokemonv2/htdocs/images_and_sprites/my_artwork/my_sprites.php[/b] on line [b]1[/b]

[b]Warning:[/b] include(../top.txt) [function.include]: failed to open stream: No such file or directory in [b]/www/uuuq.com/a/k/p/akpokemonv2/htdocs/images_and_sprites/my_artwork/my_sprites.php[/b] on line [b]1[/b]

[b]Warning: include() [function.include]: Failed opening '../top.txt' for inclusion (include_path='.:/usr/lib/php') in [b]/www/uuuq.com/a/k/p/akpokemonv2/htdocs/images_and_sprites/my_artwork/my_sprites.php[/b] on line [b]1[/b]


Basically, though, I just don't know how to reference back to the root directory, which is all someone needs to tell me how to do. smile.gif I've seen some of these
CODE
$ROOT_

something-or-others flying around, but I don't know...tongue.gif
swordz
. actually means go down one level (I believe), so try .../

swordz
akpokemon
QUOTE(swordz @ Dec 24 2008, 10:29 AM) *
. actually means go down one level (I believe), so try .../

swordz


Well, I figured out that
CODE
../
means to go up one level, so when I did the code
CODE
../../
, it went up 2 levels, which is the parent directory, so it worked!

So for those interested, the full coding I used to include my navigation menu was
CODE
<?php include('../../name_of_html_document_here.txt'); ?>
,which went up 2 levels in the folder system. And of course, it's not always going to be .txt. It'll be the file type of the file that you're including (obviously)

Thanks again, though!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.