Adding CSS using function in PHP -


i try add css file html file using statistic function this:

      public static function addcss($file){          $csspath = $_server['document_root']. directory_separator. 'new'.           directory_separator. 'css/'.$file;            return file_exists($csspath) ? "    <link rel=\"stylesheet\" href=\"$csspath\" type=\"text/css\"      media=\"screen\" charset=\"utf-8\" />     " : "css file not found";         } 

but doesn't work expected. want produce csspath "http:localhost/new/css/admin.css when i'm called using general::addcss('admin.css'); got address make me fail include: c:/xampp/htdocs\new\css/admin.css. how can fix addressing?

you using xampp, document root path "server". thats why path wrong. need exclusively specify path want, until move server.

also, if using shared hosting plan, document root not work of time. set constant server root path can use use document_root.

     //create root path      define('root', 'something/anotherthing/public_html');       public static function addcss($file){      //use root path everywhere instead of document_root      $csspath = root . directory_separator. 'new'.       directory_separator. 'css/'.$file;        return file_exists($csspath) ? "      <link rel=\"stylesheet\" href=\"$csspath\" type=\"text/css\" media=\"screen\" charset=\"utf-8\" />      " : "css file not found";     } 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -