LuVu
LuVu

Reputation: 1088

PHP include path ignored in HTML file

I have a lot of css/javascript file that I'm using on mutiple pages. So I included them in my php file.

styles.php :

<?php
# SCRIPTS/CSS BEGIN | DEBUT DES SCRIPTS/CSS
include'css/base.css';
include'/css/style.css';
include'/css/base2.css';
include'/css/style-menu.css';
# SCRIPTS/CSS ENDS | FIN DES SCRIPTS/CSS


# SCRIPTS/JS BEGIN | DEBUT DES SCRIPTS/JS
include'/js/base.js';
include'/js/menu.js';
# SCRIPTS/JS ENDS | FIN DES SCRIPTS/JS
?>

Now, on my html pages I'm trying to include the styles.php file. However I'm not able to do it.

My file is located to this path: /opt/lampp/htdocs/src/php/styles.php

This is the path of the html file: /opt/lampp/htdocs/src/html/index.html

I tried to use the followings code but none of them succeed:

<?php include '/src/php/styles.php'; ?>

<?php include '/php/styles.php'; ?>

<?php include './php/styles.php'; ?>

I get the following error.

Warning: include(./php/pi-ip-en.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/src/html/index.html on line 29

Please let me know what's wrong. It looks like it ignores my path, thanks.

Upvotes: 0

Views: 59

Answers (1)

Jnt0r
Jnt0r

Reputation: 173

You can't include files in html with php. You need to insert a link or script tag with the specific href or src attribute using php.

...
echo '<link rel="stylesheet" href="' . $yourUrlHere . '">';
...

Upvotes: 1

Related Questions