vinpkl Posted November 30, 2008 Share Posted November 30, 2008 hi all i m having problem with require_once 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 in file2 inside folder2. i m not able to understand as we use this "../" if the file is inside in any folder on root. thanks vineet Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 30, 2008 Share Posted November 30, 2008 Start all your image paths with a / so they load up from the root of your site. eg <img src="/path/to/image" /> Quote Link to comment Share on other sites More sharing options...
vinpkl Posted November 30, 2008 Author Share Posted November 30, 2008 hi wildteen88 i have tried it many times. but if i change my images path in header.php to <img src="/images/home_icon.gif" alt="" width="13" height="12" style="padding-bottom:5px" /> and included this header.php file with <?php require_once("../included_files/header.php");?> or <?php require_once("included_files/header.php");?> then the images inside header.php disappear from all files whether they are inside of any folder or not. vineet Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2008 Share Posted November 30, 2008 Post your actual code that does not work for both the main file and the header.php file. You are doing something in them that you are not showing us that is preventing either the require_once from working or the <img tag from being output correctly. Quote Link to comment Share on other sites More sharing options...
jscix Posted November 30, 2008 Share Posted November 30, 2008 If you use, /path/to/image then your going to have to use the FULL path. /var/www/mywebsite/root/images/image.jpg Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2008 Share Posted November 30, 2008 The browser requests images using a URL. A leading / on a URL refers to the domain root folder. A file system path has no meaning in an <img src="url_of_an_image_here"> tag. http://w3schools.com/html/html_images.asp Quote Link to comment Share on other sites More sharing options...
vinpkl Posted November 30, 2008 Author Share Posted November 30, 2008 hi PFM I have been testing this with small code files and those are given below This is my header.php code <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 echo "Welcome ".$_SESSION['user_name']; ?></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> This is my success.php inside a folder on root where the images of header.php disappear <?php require_once("../config.php"); $unique_id = session_id(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>gadgetsonline.co.nz</title> <link rel="stylesheet" type="text/css" href="includes/styles.css" /> </head> <body> <table width="901" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td valign="top"><?php require_once("../included_files/header.php");?></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="550" height="25" valign="top" class="heading_green"><img src="images/heading_icon.gif" alt="" /> CUSTOMER REGISTRATION </td> </tr> <tr> <td align="left" valign="top" class="shadow"> </td> </tr> <tr> <td align="left" valign="top" style="padding-left:15px;"><p>Welcome to gadgetsonline.co.nz. <br /> <br /> You have been successfully registered with our company : <br /> </p> </td> </tr> <tr> <td align="left" valign="top" style="padding-left:15px;"></td> </tr> </table></td> <td valign="top" class="green_sep" style="width:20px"><img src="images/left_sep.gif" alt="" width="24" height="1" /></td> </tr> </table></td> </tr> </table></td> </tr> <tr> <td style="padding-left:7px"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center" valign="middle" class="footer"><?php require_once("../included_files/footer.php");?></td> </tr> </table></td> </tr> </table> </body> </html> please do let me know if anything else i can provide to make my self clear. vineet Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2008 Share Posted November 30, 2008 Are you actually getting the box with the red-x in it for the images or something else? Is this on a live server that you could post a link to? I suspect the problem is invalid HTML. The posted code has two opening <table> tags and only one closing </table> tag. Also, the header.php file you posted on a different forum has a query in it that is outputting <td></td> tags inside of other <td></td> tags, but only when the query works and has any matching rows. This could cause a browser to not render the content of the cells properly. Quote Link to comment Share on other sites More sharing options...
vinpkl Posted November 30, 2008 Author Share Posted November 30, 2008 hi PFM yes i m getting a red cross X on the images that are not shown. sorry its not on a live server. its on my localhost. i have deleted that <table> tag. but it hadnt made any diference in view of the images. here is the corect code of header.php with just one php code included. <table width="90%" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="11" style="color:#FFFF00" align="right"> <?php echo "Welcome ".$_SESSION['user_name']; ?></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> when i view source my success.php file that is inside the folder on root then its images path is <img src="images/home_icon.gif" alt="" width="13" height="12" style="padding-bottom:5px" /> the images path is setting wrong that why its not getting the images to show but if add ../ with images in header.php then the files which are outside any folder on root they dont show images. vineet Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.