Page 1 of 1
slash problems using Linux and Windows
Posted: Wed Dec 22, 2004 11:57 am
by mcog_esteban
hi all.
can some explain this to me:
i got a proj from a guy that was working win linux, and when i was testing i got problems (not showing images,bad files includes,etc...), when i got the code i had to change every link like /images/aaa.gif to images/aaa.gif to see everything working well.
Can someone tell me why do i got this problem with the slashes?
There's any simple fix to resolve this?
Can i use the same code(with slahes) in both OS's?
Thanks.
Posted: Wed Dec 22, 2004 12:53 pm
by markl999
Yes, you can use forward slashes on both, eg /images/foo.gif
I use this same style on both windows and *nix (both running apache, i'm not sure if that style would be a problem on IIS .. it shouldn't make any difference though).
Posted: Wed Dec 22, 2004 1:11 pm
by mcog_esteban
but what i was telling that i had to delete the slahes to get it work on Windows.
Therefore using both slashes will not my problem.
Posted: Wed Dec 22, 2004 1:16 pm
by markl999
The slashes won't be the problem directly as forward slashes work fine on windows.
What's the exact format that produces the problem ?
When using forward slashes what output do you get (the html source) ?
Posted: Wed Dec 22, 2004 1:20 pm
by Benjamin
Well if the slashes are in the html I can't really see that as being a problem.
Posted: Wed Dec 22, 2004 1:26 pm
by mcog_esteban
nevermind...it's working now(with the slashes).
thank you both.
Posted: Wed Dec 22, 2004 1:57 pm
by rehfeld
first of all this has nothing to do w/ what os or anything, it has to do w/ filesystem structure and the document root.
ok, lets say your testing on your local machine.
your machines doc root is accessed by typing
http://localhost into the browser
when you have a file path hich BEGINS w/ a slash, you are specifying a filepath relative to a root directory
lets say your html page is on
http://example.com/testing/foo/bar.html
now in bar.html, if you link to images like this
src="images/apple.gif"
the browser will look for a file at
http://example.com/testing/foo/images/apple.gif
BUT if you link like this
src="/images/apple.gif"
the browser will look for the file at
http://example.com/images/apple.gif
the leading slash means relative to the root
same goes for filesystem operations in php or anything else
if your script is at
C:/foo/bar/your_doc_root/index.php
and in index.php you call
include '/script.php';
you are calling the file
C:/script.php
again, the leading slash makes it relative to the root directory
this is same on all OS as far as i know.
so the person who was working before you just had his filesystem structure, and his webservers document root different than yours.
me personally, i ALWAYS write images paths with a leading /. that way no matter what url the user is on in my site, it works
same goes for includes in php, i make my own "root" like so
Code: Select all
include $_SERVER['DOCUMENT_ROOT'] . '/path/to/script.php';
Posted: Wed Dec 22, 2004 5:43 pm
by timvw
some handy php constants:
Code: Select all
<?
echo PHP_OS;
echo DIRECTORY_SEPARATOR;
?>