...

View Full Version : images not showing with require_once



vineet
11-30-2008, 01:22 PM
hi all

i m having problem with including files and images geting disappear.

i have images folder on the root.
i have header.php in my included_files folder on root.

if i include header.php in my files that are on the root with this code


<?php require_once("included_files/header.php");?>


then all the images of the header.php are shown perfectly alright.

But

if i include header.php in my files that are inside any folder on the root with this code


<?php require_once("../included_files/header.php");?>


then all the images of the header.php are not shown. they disappear.


Like i have folder2 on root. and there is file2 inside folder2. Then i used this code


<?php require_once("../included_files/header.php");?>


to include my header file. but with this code my images of header.php file disappear.

i m not able to understand as we use "../" if the file is inside in any folder on root.


thanks
vineet

djm0219
11-30-2008, 01:39 PM
How are you referencing the images in header.php?

vineet
11-30-2008, 01:52 PM
How are you referencing the images in header.php?

hi djm

my header.php has images path as



<img src="images/login_icon.gif" alt="" width="21" height="18" style="padding-bottom:5px" />


images folder is on the root. And header.php is inside included_files folder.

vineet

djm0219
11-30-2008, 02:44 PM
Since your images folder is off of your root try changing your img tags to
<img src="/images/login_icon.gif" alt="" width="21" height="18" style="padding-bottom:5px" />

Things are working the way they are now because the calling program that is including header.php is in the root of your site and the images are being found below that program. Adding the leading slash to the img tag will force them to always be looked for starting in the root of the site. It's the extra directory level that is causing what you are currently using to not work.

vineet
11-30-2008, 02:55 PM
Since your images folder is off of your root try changing your img tags to
<img src="/images/login_icon.gif" alt="" width="21" height="18" style="padding-bottom:5px" />

Things are working the way they are now because the calling program that is including header.php is in the root of your site and the images are being found below that program. Adding the leading slash to the img tag will force them to always be looked for starting in the root of the site. It's the extra directory level that is causing what you are currently using to not work.


hi dave

i had already tried it many times.
adding slash before the path makes the images disappear in all pages of the complete website whether the page is in the folder or outside the folder on root.

vineet

CFMaBiSmAd
11-30-2008, 03:27 PM
Is the HTML in your require_once files present? When you do a "view source" in your browser what is present at the point where the <img ....> tags should be?

Browsers request image files. As long as the URL the browser uses is correct, the image will work. The leading / should have worked if your images folder is in the document root folder. Are you doing any URL rewriting? Is there any conditional logic either in your main file surrounding the require_once statements or conditional logic in your header.php file surrounding the <img ...?> tag? You would need to post more of your actual code in your main file and your header.php file to get more specific help with what they might be doing that is not working.

I suspect that your require_once or some logic is failing. Add the following two lines of code immediately after your first opening <?php tag in your main file -


ini_set ("display_errors", "1");
error_reporting(E_ALL);

Also, have you cleared your browser's cache? You might have broken images cached, instead of the actual working images.

vineet
11-30-2008, 03:57 PM
Is the HTML in your require_once files present? When you do a "view source" in your browser what is present at the point where the <img ....> tags should be?

Browsers request image files. As long as the URL the browser uses is correct, the image will work. The leading / should have worked if your images folder is in the document root folder. Are you doing any URL rewriting? Is there any conditional logic either in your main file surrounding the require_once statements or conditional logic in your header.php file surrounding the <img ...?> tag? You would need to post more of your actual code in your main file and your header.php file to get more specific help with what they might be doing that is not working.

I suspect that your require_once or some logic is failing. Add the following two lines of code immediately after your first opening <?php tag in your main file -


ini_set ("display_errors", "1");
error_reporting(E_ALL);

Also, have you cleared your browser's cache? You might have broken images cached, instead of the actual working images.

hi CFM

like i have index.php on the root. i have view source my html of index.php and it shows the correct path of images folder on root.


<img src="images/home_icon.gif" alt="" width="13" height="12" style="padding-bottom:5px" />


i included those two lines that u provided for error check and then added a slash before images folder


<img src="/images/home_icon.gif" alt="" width="13" height="12" style="padding-bottom:5px" />


with this code no error is displayed and no image is dispalyed.

i have few lines of php code in my header.php and i m not using any url rewriting.
here is my full header.php source


<table width="901" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="300"><img src="images/logo_gadgets.gif" alt="" width="275" height="81" /></td>
<td width="750" align="right" style="padding-top:5px;padding-bottom:8px;"><table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="11" style="color:#FFFF00" align="right"> <?php
$qry="select * from special_offers";
$result = mysql_query($qry);
if(mysql_num_rows($result)>0)
{
while($row=mysql_fetch_array($result))
{
echo "<td>". "<img height=200 width=250 src='admin/uploads/" . $row['offer_image'] . "'/>" . "</td>";
echo "<td class=green_sep>". "<img src='images/spacer.gif' width=15 height=2 />" . "</td>";
}
}
?></td>
</tr>
<tr>
<td align="center" valign="bottom" style="padding-right:10px; width:40px;"><img src="images/home_icon.gif" alt="" width="13" height="12" style="padding-bottom:5px" /><br />
<a href="index.php" class="toplink">HOME</a></td>
<td width="3"><img src="images/topnav_sep.gif" alt="" width="3" height="45" /></td>
<td align="center" valign="bottom" width="110"><img src="images/email_icon.gif" alt="" width="16" height="11" style="padding-bottom:5px" /><br />
<a href="contactus.php" class="toplink">CONTACT US</a></td>
<td width="3"><img src="images/topnav_sep.gif" alt="" width="3" height="45" /></td>
<td align="center" valign="bottom" width="130"><span style="color:#FFFFFF"><br /><img src="images/cart_icon.gif" alt="" width="20" height="16" style="padding-bottom:5px" /><br />
<a href="shopping_cart.php" class="toplink">SHOPPING CART </a></td>
<td width="3"><img src="images/topnav_sep.gif" alt="" width="3" height="45" /></td>
<td align="center" valign="bottom" style="width:85px"><img src="images/register_icon.gif" alt="" width="21" height="18" style="padding-bottom:5px" /><br />
<a href="customer_register.php" class="toplink">REGISTER</a></td>
<td width="3"><img src="images/topnav_sep.gif" alt="" width="3" height="45" /></td>
<td align="center" valign="bottom" style="width:70px"><img src="images/login_icon.gif" alt="" width="21" height="18" style="padding-bottom:5px" /><br />
</td>
<td width="3"><img src="images/topnav_sep.gif" alt="" width="3" height="45" /></td>
</tr>
</table>



please do let me know if i can make my self clear with any other code

vineet



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum