0

I'm trying to autoload the stylesheets in my page but it isn't working it returns this in the console:

Resource interpreted as Stylesheet but transferred with MIME type text/html

I've found what the problem is but I'm not sure how to fix it yet. As the autoloader works on one page but not on the other.

Working page:

Request URL:http://php.dev/public/assets/css/custom.css

This is the correct url but on my other page it is:

Request URL:http://php.dev/riot/public/assets/css/custom.css

So for some reason it adds a part of the url 'riot' in the request url I'm not sure how to remove this so it could load the css style correctly.

Autoloader function:

public function loadCss(){
    $folder = glob('./public/assets/css/*.{css}', GLOB_BRACE);
    foreach ($folder as $filename) {
        echo "<link type='text/css' rel='stylesheet' href='".$filename."'>";
    }
}
ThomH
  • 498
  • 2
  • 6
  • 14
  • Is the CSS file being included in different files located in different directories? – kojow7 Jun 19 '16 at 06:08
  • @kojow7 all css files in the folder are being included, none of them work. They are being included from http://prntscr.com/bi6muo – ThomH Jun 19 '16 at 06:10
  • Any chance of seeing the HTML part where you are rendering ` – Tigger Jun 19 '16 at 06:12
  • @Tigger echo $filename returns this http://prntscr.com/bi6npm – ThomH Jun 19 '16 at 06:14
  • 1
    That seems like your problem to me. That is nothing like `/public/assets/css/custom.css`. – Tigger Jun 19 '16 at 06:15
  • @ThomH I think you understood my question a bit backwards. What I'm asking is if some of the PHP files are located in different directories. i.e. are some of the PHP files located inside the riot directory and others located outside of it? – kojow7 Jun 19 '16 at 06:16
  • Yes, agree with Tigger. Remove the . before the /public and it should hopefully work in your case. – kojow7 Jun 19 '16 at 06:18
  • @kojow7 Sorry for the misunderstanding. Yes that's the case they are in different directories. i've already trying to remove the first dot and then put php.dev infront of it but then it gives the url which i posted in the main post – ThomH Jun 19 '16 at 06:19
  • So for some reason if im on the page: php.dev/home it works fine but when im at php.dev/riot/euw it does not work anymore – ThomH Jun 19 '16 at 06:20
  • And what if you use `glob($_SERVER['DOCUMENT_ROOT'].'/public/assets/c...` instead? – Tigger Jun 19 '16 at 06:22
  • @tigger Then it tries to access the file all the way from my C: which causes this error Not allowed to load local resource: file:///C:/wamp/www/PHP/public/assets/css/bootstrap.css – ThomH Jun 19 '16 at 06:25
  • Correct! Now your job is to fix that. How are you going to do it? There are a few ways that I can think of for doing this but I don't know your needs or your environment. Anyway, the "fix" from here is not hard. – Tigger Jun 19 '16 at 06:28
  • @Tigger Will do ! thanks alot for the help :) – ThomH Jun 19 '16 at 06:29
  • @Tigger Hi, Its now echoing the correct path but when I try to include it into the page it again says: Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://php.dev/riot/php.dev/public/assets/css/bootstrap.css". But the url which is in the console error is different from the one i echo because im echoing php.dev/public/assets/css/bootstrap.css – ThomH Jun 19 '16 at 07:02
  • This issue has [many answer on StackOverflow](http://stackoverflow.com/search?q=Resource+interpreted+as+Stylesheet+but+transferred+with+MIME+type) – Tigger Jun 19 '16 at 07:36
  • Possible duplicate of [Resource interpreted as stylesheet but transferred with MIME type text/html](http://stackoverflow.com/questions/10553638/resource-interpreted-as-stylesheet-but-transferred-with-mime-type-text-html) – Tigger Jun 19 '16 at 07:37
  • @Tigger I've already added that line in my .htaccess but it doesn't work – ThomH Jun 19 '16 at 07:53
  • @Tigger I think i need to add header('Content-Type: text/css; charset=UTF-8'); before my echo – ThomH Jun 19 '16 at 08:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/115029/discussion-between-tigger-and-thomh). – Tigger Jun 19 '16 at 08:14

0 Answers0