I'm needing to include a file from the parent directory, and other sub-directories, into a sub-directory. I've done it before by simply using include('/rootdirectory/file.php'); but now it won't seem to work.
Just wondering how I can do this, thanks.
Here's my exact line:
include('/forums/groups.php');
It's giving me this error(the page still runs):
Warning: include(/forums/groups.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\forums\blog\posts.php on line
Warning: include() [function.include]: Failed opening '/forums/groups.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\forums\blog\posts.php on line 3
If the referenced object is a folder, the function will return the parent folder of that folder. For the current folder of the current file, use $current = dirname(__FILE__); . For a parent folder of the current folder, simply use $parent = dirname(__DIR__); .
2. With a directory, a parent directory is a directory containing the current directory. For example, in the MS-DOS path below, the "Windows" directory is the parent directory of the "System32" directory, and C:\ is the root directory.
You need to try the path of functions. php within the system and not its url. Do you have console access? If so just find out what directory is the file in and include it using the full path.
There is no way to go to the parent folder right out of the search results, as that is not how it operates, however if you double-click on the quick launch search result, resulting in navigating to the folder, then press alt+up then it will go to the parent folder.
include()
and its relatives take filesystem paths, not web paths relative to the document root. To get the parent directory, use ../
include('../somefilein_parent.php'); include('../../somefile_2levels_up.php');
If you begin with a /
, an absolute system file path will be used:
// Full absolute path... include('/home/username/sites/project/include/config.php');
If your server is not resolving the file from the parent directory using
include '../somefilein_parent.php'
try this (using the parent directory relative to the script):
include __DIR__ . "/../somefilein_parent.php";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With