Results 1 to 4 of 4

Thread: images not showing with require_once

  1. #1
    Join Date
    Jun 2008
    Posts
    121
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default 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. #2
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Thumbs down

    I have had the same problem and have never really found a solution I was totally happy with.

    I eventually decided to NOT use ../ to navigate in and out of directories when including files.

    I think the following is the best solution:

    Code:
    <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/includes/header.php"); ?>
    And for html within the header that references your pictures, do this:

    Code:
    <img src="/images/picture.jpg" alt="" width="258px" height="149px" />
    src="/" When you start with the forward slash, you can build the file reference from the public web root (www or public_html). For example, you can link to index.php (the "home page") by simply doing this:

    Code:
    <a href="/">Link to home page</a>
    If anyone else has any ideas about this I would love to hear them too. This is something I struggled with before until I came up with the above solution. But again, I am not convinced it is the best solution.

    Good Luck,

    Jason

  3. #3
    Join Date
    Jun 2008
    Posts
    121
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default images not showing

    hi jason

    if i use
    Code:
    <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/included_files/hdr.php"); ?>
    then the header file get missed. i get mysql error

    Warning: require_once(E:/xampp/htdocs/included_files/hdr.php) [function.require-once]: failed to open stream:

    vineet

  4. #4
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    I should have asked what your directory structure is. I assumed "included_files" was under your public web root (htdocs).

    If "included_files" is above, then go back to the way you were doing things, but when you place an image in html code, do what I suggested in my first reply <img src="/images/picture.jpg" />

    Jason

Bookmarks

Posting Permissions

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