PHP help

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

Simple problem I don't know how to fix.

I have a folder called includes where my php wrapper is. Now, I have another folder called seotools and I have a file in it. To add the wrapper to the file I use this code. And it doesn't work. I have always had a file structure where all my files are in the same www directory, no folder. But I need to be more organized now.

<?php include('/includes/wrapper.php'); ?>'

This is what the file tree looks like

www
Includes
----header.php
----footer.php
----navigation.php
----wrapper.php
Seotools
----index.php - this file needs the php wrapper

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

the / will make the root directory the root of the whole filesystem, not just your directory. You might want to find the full path, and then have the /blahblah after the full path. you could do ./ or just omit the leading slash, and it should work fine.

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

<?php include('./includes/wrapper.php'); ?>
'

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

I tried that and I get the same error

Warning: main(./includes/wrapper.php): failed to open stream: No such file or directory in c:\appserv\www\ieffective\seotools\goodkeywords.php on line 8

Warning: main(./includes/wrapper.php): failed to open stream: No such file or directory in c:\appserv\www\ieffective\seotools\goodkeywords.php on line 8

Warning: main(): Failed opening './includes/wrapper.php' for inclusion (include_path='.;c:\php4\pear') in c:\appserv\www\ieffective\seotools\goodkeywords.php on line 8

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

Now if I make the include code say this '../wrapper.php' I get this error

Warning: main(./includes/header.php): failed to open stream: No such file or directory in c:\appserv\www\ieffective\includes\wrapper.php on line 1

Warning: main(./includes/header.php): failed to open stream: No such file or directory in c:\appserv\www\ieffective\includes\wrapper.php on line 1

Warning: main(): Failed opening './includes/header.php' for inclusion (include_path='.;c:\php4\pear') in c:\appserv\www\ieffective\includes\wrapper.php on line 1

Warning: main(./includes/navigation.php): failed to open stream: No such file or directory in c:\appserv\www\ieffective\includes\wrapper.php on line 2

Warning: main(./includes/navigation.php): failed to open stream: No such file or directory in c:\appserv\www\ieffective\includes\wrapper.php on line 2

Warning: main(): Failed opening './includes/navigation.php' for inclusion (include_path='.;c:\php4\pear') in c:\appserv\www\ieffective\includes\wrapper.php on line 2

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

The wrapper code looks like this

<div id="header.php"><?php include('./includes/header.php');?></div>
<div id="navigation.php"><?php include('./includes/navigation.php'); ?></div>
'

CptAwesome's picture

He has: 370 posts

Joined: Dec 2004

if you include a file, the relative paths are not retained from its inclusion directory, so you should make it this:

<div id="header.php"><?php include('../includes/header.php');?></div>
<div id="navigation.php"><?php include('../includes/navigation.php'); ?></div>
'

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.