include not working
I don't get it 😦
I'm using include for every page to get my server and my header.
But on one reason doesn't work on this page…
my folder structure for this file is:
|-- assets/
| |-- css/
| |-- js/
| |-- images/
|
|-- includes/
| |-- header.php
| |-- footer.php
| |-- server.php
|
|-- pages/
| |-- admin/
| |-- kruiske-online.php this is the file where it doesn't work
| |-- settings.php
| |-- home.php
Is there anyone that knows how I can fix this?
Ps. I got these error messeges:
Warning: include(C:\xampp\htdocs\twt-app.dev\pages\admin../../Includes/server.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\twt-app.dev\pages\admin\kruiske-online.php on line 2
Warning: include(): Failed opening 'C:\xampp\htdocs\twt-app.dev\pages\admin../../Includes/server.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\twt-app.dev\pages\admin\kruiske-online.php on line 2
Warning: include(./Includes/header.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\twt-app.dev\pages\admin\kruiske-online.php on line 3
Warning: include(): Failed opening './Includes/header.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\twt-app.dev\pages\admin\kruiske-online.php on line 3
Warning: include(./Includes/footer.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\twt-app.dev\pages\admin\kruiske-online.php on line 10
Warning: include(): Failed opening './Includes/footer.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\twt-app.dev\pages\admin\kruiske-online.php on line 10
9 Replies
It's probably case sensitive
Ah, and you're trying to include from ./,which is the current working directory, and that's not where the includes folder lives
But I have try every other path. ../ or even the whole path of my directory. And even that would not work?
have you tried with a lower case i?
yes I tried but doesn't work
if your folder structure is correct, the include should be
include('../../includes/header.php');
It works! 😄
Thank you! Can I actually use this path for every file? Regardless of which folder it is in?
no, that's a relative path.
..
represents the parent folder, so that path will go two levels up, then into includes
the alternative is an absolute path, which can be finnicky on windows too, and you also don't want to hard code that because you probably have a different path on your development machine than you do on productionokay then I know 🙂 Thanks! then I can continue
instead of doing all that weird path traversal, you can use the
$_SERVER['DOCUMENT_ROOT']
variable, or maybe store it in a constant ending with DIRECTORY_SEPARATOR
appended to it