problem using 'include' file: path not working!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hvolvo
Forum Newbie
Posts: 6
Joined: Thu Mar 27, 2008 2:01 am

problem using 'include' file: path not working!

Post by hvolvo »

hi!
problem explanation:
in my root directory i have the 'header.php' file which has two image tags, these images are stored in a directory named images in the same root dir.
header.php:
<div id="header">
<table width="100%" >
<tr>
<td class="logo">
<img src="images/logo.png" height=80 width=90>
</td>
<td class="title">
<img src="images/title.png" height="80" width="300"/>
</td>
</tr>
</table>
</div>


the header looks fine in the 'index.php' page of the root dir. now i created a directory called 'users' within the root dir in which i created a file called 'new_user.php'. here i included the 'header.php' file, but it shows only a thin background. the images are not visible.

directory structure:
root
|_images
| |_logo.png
|
|_users
| |_new_user.php
|
|_header.php
|_index.php


i suppose it is because it cannot access the images folder from within the users folder.
is there any way i could use some path variable to solve this problem?
PLZ suggest a solution
DeFacto
Forum Commoner
Posts: 37
Joined: Wed Apr 23, 2008 2:30 pm

Re: problem using 'include' file: path not working!

Post by DeFacto »

header.php:

Code: Select all

 
div id="header">
<table width="100%" >
<tr>
<td class="logo">
<img src="<?php echo $path; ?>/logo.png" height=80 width=90>
</td>
<td class="title">
<img src="<?php echo $path; ?>/title.png" height="80" width="300"/>
</td>
</tr>
</table>
</div>
 
index.php:

Code: Select all

 
<?php
$path="images";
include 'header.php';
?>
 
new_user.php:

Code: Select all

 
<?php
$path="../../images";
include 'header.php';
?>
 
try that.
hvolvo
Forum Newbie
Posts: 6
Joined: Thu Mar 27, 2008 2:01 am

Re: problem using 'include' file: path not working!

Post by hvolvo »

Thanx a lot DeFacto! it works great :D
Post Reply