PHP Warning: include_once () Failed to open '' for inclusion (include_path = '; C: \ xampp \ php \ PEAR')

I know that this error is very common, I tried to search Google, I did the tricks to no avail. So, my setup, I have 3 directories:

CLASSES → constants
PAGES
INITCONTROLS

EDIT: I have a new error:

* Warning: require_once (initcontrols / config.php) [function.require-once]: could not open the stream: there is no such file or directory in *

below is my code snippet:

require_once("initcontrols/config.php"); <div> <?php $file = "initcontrols/header_myworks.php"; include_once($file); echo $plHeader;?> </div> 

What else is missing here? Thank you for your help in advance.

+6
source share
4 answers

This should work if the current file is in the same directory as initcontrols :

 <?php $ds = DIRECTORY_SEPARATOR; $base_dir = realpath(dirname(__FILE__) . $ds . '..') . $ds; require_once("{$base_dir}initcontrols{$ds}config.php"); ?> <div> <?php $file = "{$base_dir}initcontrols{$ds}header_myworks.php"; include_once($file); echo $plHeader;?> </div> 
+6
source

The inclusion path is set in accordance with the server configuration ( PHP.ini ), but the specified include path refers to this path, so in your case include path (the actual path in the windows):

 C:\xampp\php\PEAR\initcontrols\header_myworks.php 

so that the path you inserted into the object is correct. Make sure your file is there.

For more information, you can get and set the program path of inclusion.

+2
source

Paste this into config.php

 $config['rewrite_short_tags'] = FALSE; 
0
source

This is because you are using a relative path.

An easy way to fix this is with the magic constant __DIR__ , for example:

 require_once(__DIR__."/initcontrols/config.php"); 

From a PHP document:

File directory. If used inside include, then the returned file directory is returned

0
source

All Articles