-1

I want to load CSS files with an array and a foreach loop,

<?php
    define("DS",DIRECTORY_SEPARATOR);
    define("APP_PATH",__DIR__);
    define('CSS_PATH',APP_PATH.DS."assets".DS.'css'.DS);
     $css_files = array('font-awesome.min.css','bootstrap.min.css','normalize.min.css'
                          ,'owl.carousel.min.css','main.css');
        foreach($css_files as $css){?>
          <link rel="stylesheet" href="<?php echo CSS_PATH.$css?>"/>
          <?php } ?> 

but the browser prevents loading with an array:

Not allowed to load local resource: file:///E:/programs/Xampp/htdocs/LOCA_PDO/assets/css/font-awesome.min.css

    Not allowed to load local resource: file:///E:/programs/Xampp/htdocs/LOCA_PDO/assets/css/bootstrap.min.css

    Not allowed to load local resource: file:///E:/programs/Xampp/htdocs/LOCA_PDO/assets/css/normalize.min.css

    localhost/:44 Not allowed to load local resource: file:///E:/programs/Xampp/htdocs/LOCA_PDO/assets/css/main.css

CSS arrays

X Squared
  • 5
  • 3
Eng_Farghly
  • 1,987
  • 1
  • 23
  • 34
  • 1
    Have a look at the HTML source code, is it what you expect it to be? – KIKO Software Aug 30 '17 at 08:16
  • Use some other browser than chrome, it can be a browser security limitation. Plus, you might find a solution in [here](https://stackoverflow.com/questions/34901523/file-url-not-allowed-to-load-local-resource-in-the-internet-browser) – Sina Aug 30 '17 at 08:18
  • @KIKOSoftware of course – Eng_Farghly Aug 30 '17 at 08:19
  • @KIKOSoftware I update question – Eng_Farghly Aug 30 '17 at 08:34
  • That's PHP source code, not HTML source code. You can view the HTML source code in your browser, often by right clicking on the page and select 'View Page Source' from the local menu. – KIKO Software Aug 30 '17 at 08:35
  • 1
    "browser prevent loading with array" — Look at the **error message**. It tells you why it isn't loading the files and it has nothing to do with the array. – Quentin Aug 30 '17 at 08:36

1 Answers1

0

Try using relative path:

<link rel="stylesheet" media="all" href="/CSS/Style.css" type="text/css" />

You need to change

define('CSS_PATH',APP_PATH.DS."assets".DS.'css'.DS);

to

define('CSS_PATH',DS."assets".DS.'css'.DS);

This is assuming LOCA_PDO is the root of your website

Milan Chheda
  • 8,159
  • 3
  • 20
  • 35