2

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 }

4 Answers4

8

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
  • 7,315
  • 26
  • 33
  • 2
    "dirname(__FILE__) is appropriate for including script files server-side, but not for paths used by the client." thanks did'nt know that! :) –  Nov 15 '09 at 19:29
1

edit: read the question incorrectly...

use

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

for css

Galen
  • 29,976
  • 9
  • 71
  • 89
1

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
  • 2,739
  • 1
  • 20
  • 28
0

Is this a problem with partial case-sensitivity on Mac OSX?

Community
  • 1
  • 1
conceive
  • 33
  • 1
  • 9