By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

Building portable server addresses

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Marek,

[...]
..
$S_1 = getcwd()."/images/image_1.jpg"; //BACKGROUND PICTURE It works fine but it doesn't work in FreeBSD, for example.

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

Jul 17 '05 #2

P: n/a
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
Jul 17 '05 #3

P: n/a
nc@iname.com (Nikolai Chuvakhin) wrote in message news:<32**************************@posting.google. com>...
....
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';
...
}


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
Jul 17 '05 #4

P: n/a
Karl Heinz Marbaise <kh********@gmx.de> wrote in message news:<c3*************@ID-68093.news.uni-berlin.de>...
What version of PHP on you "TEST" System and on FreeBSD ?


Windows XP - 4.3.2.
FreeBSD - 4.3.4.

Kind regards. :-)

Marek Kotowski
Warsaw
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.