views:

130

answers:

3

Hi. I have a PHP class that creates a header for my html file.. It's included, and that file is included again.. So I thought that the dirname(__FILE__) function could work.. But it says it can't find the stylesheet..

I'm using mamp on os x, and when I take the path that I get from dirname(__FILE__)./../stylesheets/stylesheet.css into the terminal, the file is found.. I'm pretty sure the path is correct.

What can be the reason for this? I use dirname(__FILE__) all the time when I include files, that works..

Thanks

EDIT:

Files and directories:
/data/main.php
/stylesheets/stylesheet.css
/public/index.php

In the main.php:
public function createHeader(){ `$stylesheetpath = dirname(__FILE__) . "/../stylesheets/stylesheet.css";` `$header = "\n";` return $header }
+7  A: 

The relative path should be ok.

<LINK REL=StyleSheet HREF="../stylesheets/stylesheet.css" TYPE="text/css">

An absolute path here would be absolute with respect to the document root, not the file system.

dirname(__FILE__) is appropriate for including script files server-side, but not for paths used by the client. Simply put, the link tag is an instruction to the browser to go ahead and request that file.

Ewan Todd
"dirname(__FILE__) is appropriate for including script files server-side, but not for paths used by the client." thanks did'nt know that! :)
Johannes
+1  A: 

edit: read the question incorrectly...

use

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

for css

Galen
+2  A: 

From you file structure, /stylesheets/ is out of the public reach, it must be placed inside the /public/ folder for the browsers to retrieve the files:

/data/main.php
/public/stylesheets/stylesheet.css
/public/index.php

Even when the file main.php is working, the file being viewed by the browser is index.php, so the relative path would be stylesheets/stylesheet.css

Ast Derek
thanks a lot :D
Johannes