Hi All,
I'm using XAMMP server in USB stick and have Web project in this structure:
F:\xampplite\htdocs\projects\Elijah

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 :)

Recommended Answers

All 7 Replies

include("./thisfile");
<link rel="stylesheet" type="text/css" media="screen" href="./style.css">
$basedir=substr("$_SERVER['SCRIPT_FILENAME']",0,strripos("$_SERVER['SCRIPT_FILENAME'],"/",0));

just some of the diff ways to find the same thing

Can you comment on code so as I ca understand better

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

commented: Great help Man! -- I'm just starting PHP +3

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

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

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

<?php
$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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.