rn10950
rn10950

Reputation: 93

PHP include() Error

I am using include to attach a navbar and a footer to pages on my site. The navbar works perfectly but the footer keeps giving me this error:

`Warning: include(C:\inetpub\wwwroot ooter.php) [function.include]: failed to open stream: Invalid argument in C:\Inetpub\wwwroot\templatewip.php on line 69

Warning: include() [function.include]: Failed opening 'C:\inetpub\wwwroot ooter.php' for inclusion (include_path='.;c:\php\includes;C:\Inetpub\wwwroot\') in C:\Inetpub\wwwroot\templatewip.php on line 69`

This is the code:

<div id="footer"> <?php include("C:\inetpub\wwwroot\footer.php"); ?> </div>

If it helps, here is the working code for the navbar:

<div class="navbar"> <?php include("C:\inetpub\wwwroot\menuembed.php"); ?> </div>

Upvotes: 0

Views: 5602

Answers (3)

Anat0m
Anat0m

Reputation: 37

Include __DIR__.'footer.php'; if it is in your main dir, otherwise add path from your root dir to footer.php. For example my main folder is htpdocs and my footer is in inc folder then you write:

include __DIR__.'/inc/footer.php'; 

sorry for,mess writing from phone

Upvotes: 0

jszobody
jszobody

Reputation: 28911

Anytime you use backslashes in a string you risk bumping into escape sequences.

See here for details: http://www.php.net/manual/en/regexp.reference.escape.php

Change your path to use forward slashes instead, and it will just work:

<?php include("C:/inetpub/wwwroot/footer.php"); ?>

Upvotes: 2

John Conde
John Conde

Reputation: 219804

\f is the escape character for a form feed. So if you have \f in your string you need to escape the slash, too:

<div id="footer"> <?php include("C:\inetpub\wwwroot\\footer.php"); ?> </div>

Upvotes: 1

Related Questions