Yes if you start with / you are @ the Document root, but normaly your code on the server is in some subfolders you can use './includes/script.php'. The point means in the actual directory the includes folder.
PHP: Relative path doesn't work
-
18-07-2023 - |
Domanda
I want to include a file called script.php
this file is in the includes
folder.
When I do this:
include('/includes/script.php');
There is nothing happend, I get a error message that the file is not found. But when I do this:
include($_SERVER['DOCUMENT_ROOT'] . '/includes/script.php');
It works!, But $_SERVER['DOCUMENT_ROOT']
returns the base path of the document right?
But why is /includes/script.php
not working? When you start a path with /
means you go to the document root right?
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow