Building portable server addresses

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marek Kotowski

    Building portable server addresses

    The problem:

    I'd like to build – with PHP – a background-image url
    on a server (Apache) (url itself or a full directory name).
    I'd like to use a portable mechanism, I mean a PHP script
    should work in Windows, Unix and Linux. In Windows I use:

    ...
    <style type="text/css">

    ..a_class
    {
    <?php
    $S_1 = getcwd()."/images/image_1.jpg"; //BACKGROUND PICTURE
    echo "background-image: url($S_1);";
    ?>
    ....

    It works fine but it doesn't work in FreeBSD, for example.

    Thank you in advance.

    Marek Kotowski
    Warsaw
  • Karl Heinz Marbaise

    #2
    Re: Building portable server addresses

    Hi Marek,

    [...][color=blue]
    > ..
    > $S_1 = getcwd()."/images/image_1.jpg"; //BACKGROUND PICTURE[/color]
    [color=blue]
    > It works fine but it doesn't work in FreeBSD, for example.[/color]
    What version of PHP on you "TEST" System and on FreeBSD ?

    Kind Regards ?
    --
    Dipl.Ing.(FH) Karl Heinz Marbaise | www.marbaise.org
    Jabba Dabba Dooh ;-) | ICQ# 135949029

    Comment

    • Nikolai Chuvakhin

      #3
      Re: Building portable server addresses

      Marek_Kotowski@ wsip.com.pl (Marek Kotowski) wrote in message
      news:<e55a62c8. 0403250344.684e 71b2@posting.go ogle.com>...[color=blue]
      >
      > I'd like to build ? with PHP ? a background-image url
      > on a server (Apache) (url itself or a full directory name).
      > I'd like to use a portable mechanism, I mean a PHP script
      > should work in Windows, Unix and Linux. In Windows I use:
      >
      > ..
      > <style type="text/css">
      >
      > .a_class
      > {
      > <?php
      > $S_1 = getcwd()."/images/image_1.jpg"; //BACKGROUND PICTURE
      > echo "background-image: url($S_1);";
      > ?>
      > ...
      >
      > It works fine[/color]

      Only when client computer and the server are one and the same...
      getcwd() returns the local name of the current working directory,
      which is meaningless when client and server run on different
      machines.

      Here are two possible options for you:

      Option One (no PHP involved, URL to the image is relative):

      .a_class
      {
      background-image: '/images/image_1.jpg';
      ...
      }

      Option Two (some PHP involved, URL to the image is absolute):

      .a_class
      {
      <?php
      echo "background-image: 'http://",
      $_SERVER['SERVER_NAME'],
      "/images/image_1.jpg';";
      ?>
      ...
      }

      Cheers,
      NC

      Comment

      • Marek Kotowski

        #4
        Re: Building portable server addresses

        nc@iname.com (Nikolai Chuvakhin) wrote in message news:<32d7a63c. 0403251013.3890 3d99@posting.go ogle.com>...
        ....[color=blue]
        > Here are two possible options for you:
        >
        > Option One (no PHP involved, URL to the image is relative):
        >
        > .a_class
        > {
        > background-image: '/images/image_1.jpg';
        > ...
        > }
        >[/color]

        It doesn't work but I changed it a little to

        background-image: url('images/image_1.jpg');

        and this version works on Windows and FreeBSD as well.

        Thank you very much.

        Regards

        Marek Kotowski
        Warsaw

        Comment

        • Marek Kotowski

          #5
          Re: Building portable server addresses

          Karl Heinz Marbaise <khmarbaise@gmx .de> wrote in message news:<c3up82$2a 6n5u$2@ID-68093.news.uni-berlin.de>...[color=blue]
          > What version of PHP on you "TEST" System and on FreeBSD ?[/color]

          Windows XP - 4.3.2.
          FreeBSD - 4.3.4.

          Kind regards. :-)

          Marek Kotowski
          Warsaw

          Comment

          Working...