0

I am facing some trouble in accessing the file from a folder.

My current scenario is: I can accces following folders:

  • localhost/testproject/
  • localhost/testproject/inc
  • localhost/testproject/news

And I have two files:

  • localhost/testproject/inc/header.php
  • localhost/testproject/news/test.php

In the header.php there are some css files included. Now the problem is that if I try to include the header.php in test.php it does not load the css files.

Marvin Emil Brach
  • 3,984
  • 1
  • 32
  • 62
Debugger
  • 491
  • 4
  • 21

2 Answers2

4

I find that out that I have to create a site url in config file and include all the css and the js files according to that site url.

config.php

define("SITE_URL",'http://localhost/testproject/');

header.php

include "config.php";

<link href="<?php echo SITE_URL; ?>css/styles.css" rel="stylesheet">

And that is it :) thanks every one for there response.

Debugger
  • 491
  • 4
  • 21
2

If I understand correctly, you have the CSS link in the header.php. The best solution is to change the link from

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

to:

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

The . takes you back to the root folder. From there you can specify the folder relative from the root folder.

Mousa Dirksz
  • 989
  • 7
  • 3
  • 1
    This is almost correct. It should be `href="/inc/style_of_header.css"`; it's a leading slash, not a leading dot, that means "go back up to the site root". – zwol Mar 09 '15 at 15:37
  • It appears that the dot means the working directory. Found it here [link](http://stackoverflow.com/questions/7591240/what-does-dot-slash-refer-to-in-terms-of-an-html-file-path-location) – Mousa Dirksz Mar 10 '15 at 11:15
  • As a relative URL, `./inc/whatever` is exactly the same as `inc/whatever`. – zwol Mar 10 '15 at 15:23