Hi All,
I'm using XAMMP server in USB stick and have Web project in this structure:

So my current working DIR is elijah. However, I don't want to write the long path "../projects/elijah/elijah.css" when linking css file or using images. I would like to use something like a function that will retrieve current working directory so that path will be
"The_function_to_get_DIR/elijah.css" I want the root to be seen virtually as elijah

Thanks for your help, and I'm ready to clarify wherever there's ambiguity :)

8 Years
Discussion Span
Last Post by Stefano Mtangoo
<link rel="stylesheet" type="text/css" media="screen" href="./style.css">

just some of the diff ways to find the same thing


Can you comment on code so as I ca understand better

First two, . is the default for current folder, as .. is parent
third one

take the current script name as known to the server and break it at the last / character
substring of the server array, from position 0 to the position of the last /
this gives the documentroot path to the current folder

Votes + Comments
Great help Man! -- I'm just starting PHP

Ok I have this code:
How do I link the CSS file using PHP in that, Instead of full CSS path I will have href="$paths/elijah.css" ?

Thanks for your valuable reply

		<title>Test Page - Elijah Ministries</title>
				$paths = getcwd();
				print $paths;
		<link rel = "sheet" style = "text/css" href = "/project/elijah/elijah.css"  />
		<table width="100%" height="450px" bgcolor="silver">
				<td class="top_header">

May be question was too vague, here is another way,
I get path of current DIR via php script

$paths = getcwd();

Then I want to use this path when linking all my image and css file
Here is my code linking the CSS file

<link rel = "sheet" style = "text/css" href = "/project/elijah/elijah.css"  />

How do I link the CSS file using $paths that is <link rel = "sheet" style = "text/css" href = "$paths/elijah.css" />

Thanks for your invaluable help


Your code

<link rel = "sheet" style = "text/css" href = "/project/elijah/elijah.css" />

shouild be

<link rel="stylesheet" type="text/css" href="/project/elijah/elijah.css" />

even before you make it

<link rel="stylesheet" type="text/css" href="./elijah.css" />

Yeah, that error is obvious, but I failed to see it. Thanks.
It is that I'm refactoring my old HTML code to incorporate PHP. However, My working folder in XAMPP ("/project/elijah/elijah.css") will not be valid when kept on server where path will be something like "/elijah.css". So I want to use path to avoid changing things in file, which is tedious work :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.