php and include-statements with images

Discussion in 'HTML' started by Jan Faerber, Sep 27, 2004.

  1. Jan Faerber

    Jan Faerber Guest

    Hello!

    php is better than frames. So I tried something with php.
    Now I have this problem that when I have an index.php file
    with an image like <img src="images/pic.png">, I have this code
    in an /includes folder e.g. a file header.php with:

    '
    ....
    <img src="images/pic.png">
    ....
    '

    and I make in the index.php file a statement like this:

    '
    ....
    <?php
    include header.php;
    ?>
    ....
    '

    I don't know if the syntax is 100% correct now but anyway
    I want to do the same with a file in another location -
    /en/index.php ... so, here the location of the images is not
    the same relative to the location of the 'main' index.php file.
    The browser can not find the images because they are
    found now in '../images/' and not in '/images/'.

    So my question is:
    How can I use the same include files
    but with different levels of folders when I want to use
    only one folder for images for instance.
    First I solved this problem by using absolute paths
    in the 'header.php' file e.g. <img src="http://213.47.90.11/images/pic.png">
    but that seems not to be the best way it can be done.

    ty
    --
    Jan

    http://213.47.90.11
    Jan Faerber, Sep 27, 2004
    #1
    1. Advertising

  2. Jan Faerber

    Toby Inkster Guest

    Jan Faerber wrote:

    > First I solved this problem by using absolute paths
    > in the 'header.php' file e.g. <img src="http://213.47.90.11/images/pic.png">
    > but that seems not to be the best way it can be done.


    Use domain-less absolute paths:
    <img src="/images/pic.png">

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Now Playing ~ ./precious_roy_band/one_million_choices.ogg
    Toby Inkster, Sep 27, 2004
    #2
    1. Advertising

  3. Jan Faerber

    Jan Faerber Guest

    Toby Inkster wrote:

    > Jan Faerber wrote:
    >
    >> First I solved this problem by using absolute paths
    >> in the 'header.php' file e.g. <img
    >> src="http://213.47.90.11/images/pic.png"> but that seems not to be the
    >> best way it can be done.

    >
    > Use domain-less absolute paths:
    > <img src="/images/pic.png">
    >


    ty
    -
    at the moment it works. But I asked because before it didn't work.
    I don't know why.

    --
    Jan

    http://213.47.90.11
    Jan Faerber, Sep 27, 2004
    #3
  4. Jan Faerber

    Jan Faerber Guest

    <veröffentlicht & per Mail versendet>

    Jan Faerber wrote:

    > Toby Inkster wrote:
    >
    >> Jan Faerber wrote:
    >>
    >>> First I solved this problem by using absolute paths
    >>> in the 'header.php' file e.g. <img
    >>> src="http://213.47.90.11/images/pic.png"> but that seems not to be the
    >>> best way it can be done.

    >>
    >> Use domain-less absolute paths:
    >> <img src="/images/pic.png">
    >>

    >
    > ty
    > -
    > at the moment it works. But I asked because before it didn't work.
    > I don't know why.
    >


    No, it does not work.
    Only if I have the header.php or buttons.php in my root directory.
    That is fine.
    Wy does it not look up the /includes folder?
    Wouldn't that be more systematic?
    And here I will get the problem again: the images are located now
    in ../images.

    --
    Jan

    http://213.47.90.11
    Jan Faerber, Sep 27, 2004
    #4
  5. Jan Faerber

    Dave Patton Guest

    Jan Faerber <> wrote in
    news:7LR5d.313014$:

    > Hello!
    >
    > php is better than frames.


    Apples are better than dogs.
    Your statement doesn't make sense, but PHP is nice,
    and Frames are evil ;-)

    > How can I use the same include files
    > but with different levels of folders when I want to use
    > only one folder for images for instance.
    > First I solved this problem by using absolute paths
    > in the 'header.php' file e.g. <img
    > src="http://213.47.90.11/images/pic.png"> but that seems not to be the
    > best way it can be done.


    Either use absolue paths such as:
    <img src="/images/pic.png">
    or, for more flexibility, use a "config file":
    - every PHP script does an include of your site's
    "config file", in which you define string variables
    that contain the filesystem path(for when you are
    using filesystem-related function) or URL path(for
    when you are dealing with URLs) for various directories.
    - use the appropriate "config file variable" in your
    scripts, rather than hardcoding any paths
    For example, if my "confif file" has been included, and
    it contains someting like:
    $MYSITE_URL_ROOT = "/"; // location of main site HTML/PHP files
    $MYSITE_URL_IMAGES = "{$MYSITE_URL_ROOT}images/"; // location of images
    then in the above example you would use:
    <img src="<?=$MYSITE_URL_IMAGES?>pic.png">

    --
    Dave Patton
    Canadian Coordinator, Degree Confluence Project
    http://www.confluence.org/
    My website: http://members.shaw.ca/davepatton/
    Dave Patton, Sep 27, 2004
    #5
  6. Jan Faerber

    Neal Guest

    On Mon, 27 Sep 2004 18:30:56 GMT, Dave Patton <> wrote:

    > Jan Faerber <> wrote in
    > news:7LR5d.313014$:
    >> php is better than frames.

    > Apples are better than dogs.
    > Your statement doesn't make sense, but PHP is nice,
    > and Frames are evil ;-)


    Are you implying that dogs are evil? ;)
    Neal, Sep 27, 2004
    #6
  7. Jan Faerber

    Dave Patton Guest

    Neal <> wrote in
    news:eek::

    > On Mon, 27 Sep 2004 18:30:56 GMT, Dave Patton <> wrote:
    >
    >> Jan Faerber <> wrote in
    >> news:7LR5d.313014$:
    >>> php is better than frames.

    >> Apples are better than dogs.
    >> Your statement doesn't make sense, but PHP is nice,
    >> and Frames are evil ;-)

    >
    > Are you implying that dogs are evil? ;)


    I was going to say "Apples are better than oranges",
    but I didn't want to get on the bad side of the
    citrus growers ;-)

    --
    Dave Patton
    Canadian Coordinator, Degree Confluence Project
    http://www.confluence.org/
    My website: http://members.shaw.ca/davepatton/
    Dave Patton, Sep 27, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neil Zanella
    Replies:
    8
    Views:
    1,169
    mfmehdi
    Oct 20, 2006
  2. Andreas Bogenberger
    Replies:
    3
    Views:
    881
    Andreas Bogenberger
    Feb 22, 2008
  3. Rajive Narain
    Replies:
    0
    Views:
    1,558
    Rajive Narain
    Sep 18, 2009
  4. Miquel Oliete
    Replies:
    4
    Views:
    154
    Miquel Oliete
    Mar 7, 2008
  5. John Crichton
    Replies:
    6
    Views:
    253
    John Crichton
    Jul 12, 2010
Loading...

Share This Page