Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    173
    Thanks
    2
    Thanked 9 Times in 9 Posts

    images not showing with require_once

    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
    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
    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
    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

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,313
    Thanks
    4
    Thanked 207 Times in 204 Posts
    How are you referencing the images in header.php?
    Dave .... HostMonster for all of your hosting needs

  • #3
    Regular Coder
    Join Date
    Jun 2008
    Posts
    173
    Thanks
    2
    Thanked 9 Times in 9 Posts

    images not showing

    Quote Originally Posted by djm0219 View Post
    How are you referencing the images in header.php?
    hi djm

    my header.php has images path as

    Code:
    <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

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,313
    Thanks
    4
    Thanked 207 Times in 204 Posts
    Since your images folder is off of your root try changing your img tags to
    Code:
    <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.
    Last edited by djm0219; 11-30-2008 at 03:47 PM. Reason: Added additional explanation for the change suggested
    Dave .... HostMonster for all of your hosting needs

  • #5
    Regular Coder
    Join Date
    Jun 2008
    Posts
    173
    Thanks
    2
    Thanked 9 Times in 9 Posts

    images not showing

    Quote Originally Posted by djm0219 View Post
    Since your images folder is off of your root try changing your img tags to
    Code:
    <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

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,151
    Thanks
    2
    Thanked 335 Times in 327 Posts
    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 -

    PHP Code:
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    Regular Coder
    Join Date
    Jun 2008
    Posts
    173
    Thanks
    2
    Thanked 9 Times in 9 Posts

    images not showing

    Quote Originally Posted by CFMaBiSmAd View Post
    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 -

    PHP Code:
    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.
    Code:
    <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
    Code:
    <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
    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
      $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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •