Ma************@wsip.com.pl (Marek Kotowski) wrote in message
news:<e5**************************@posting.google. com>...
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
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