Warning: include(../includes/db.php): failed to open stream: - php

This is the problem I am facing now Can you please suggest me to get rid of this problem. Before I have not get this problem It was working nicely now I don't know what happened the path is correct only. Anyone please solve it...
Warning: include(../includes/db.php): failed to open stream: No such
file or directory in
C:\xampp\htdocs\portfolio\admin\includes\admin_header.php on line 3
Warning: include(): Failed opening '../includes/db.php' for inclusion
(include_path='C:\xampp\php\PEAR') in
C:\xampp\htdocs\portfolio\admin\includes\admin_header.php on line 3
Warning: include(functions.php): failed to open stream: No such file
or directory in
C:\xampp\htdocs\portfolio\admin\includes\admin_header.php on line 4
Warning: include(): Failed opening 'functions.php' for inclusion
(include_path='C:\xampp\php\PEAR') in
C:\xampp\htdocs\portfolio\admin\includes\admin_header.php on line 4

Based on the error posted, it seems to be that the include_path is referring to the path (include_path='C:\xampp\php\PEAR') while the PHP files are included in some other folder.
You need to update the include_path variable to point to the correct location. You can find this in the php.ini file.

Computers don't lie, if it says it doesn't see it, then it is not there
Make sure you are making it look at the right place, and if I will advise you do it manually also to confirm
I also suspect it is an issue arising from using relative paths. Please make sure the path is right considering where you are currently calling the file from
e.g calling include(../includes/db.php) from index.php is different from calling it from admin/index.php
EDIT
If your are calling from C:\xampp\htdocs\portfolio\admin\includes\admin_header.php to C:\xampp\htdocs\portfolio\includes
then
include(../../includes/db.php);
is the right syntax to use
Hope this Helps

I have had this the same issue before and it ended up being something dumb on my part i forgot to start the MySQL on the XAMPP control panel. I'm sure i'm late the the party on the answer but hope it can help someone later down the road.

a bit late but i just reply for those who might get the same error .
assuming you are storing header.php in your includes directory and its not beside your index.php,so when you include bd.php into your header.php and then including your header.php into your index.php pay attention that apache knows index.php direcotroy as your pwd so if you have set that relative path for db.php based on header.php directory its not gonna work.you can use absolute path to avoid this or just set you relative path based on relative location of db.php from index.php

It look likes, the files you are trying to include in your php codes, are not on that place. Try to save all your include files in a particular folder and then call it wherever you want to call it.
suppose your index.php file is in xampp/htdocs/your_folder_name/index.php , then simply create a folder name whatever you want to name it inside your folder name your_folder_name/your_new_folder and save all your files which you want to include, as if you are saving db.php then call it on the top of your page as:
<?php include("your_new_folder/db.php");?>

This has to do with how you are coding your relative path.
I am assuming you got this error when your app made reference to admin_header.php, which has an include() to try and call {document_root}/porfolio/admin/includes/db.php. My educated guess is it contains your implementation of the connection string to the database.
The correct relative path should be: include('../../includes/db.php');
This link should give you a better understanding of relative paths (and paths in general).
https://phpdelusions.net/articles/paths

In case this helps anyone else, I had this problem and then realised WAMP had crashed (or maybe I didn't start it). Either way, WAMP wasn't running on my local machine, so... doh.
This should be the very first thing you check (in line with, "is it plugged in?").

Try removing relative paths ("../")
e.g. change include(../includes/db.php) to include(includes/db.php)

Related

../ on URL on php not working

this is kind of a silly question, but as I can't sort it out I thought it might be good to get some help. The point is that the ".. /" to go back directory is not working.
The file I'm executing is in a folder that's on the main route and I need to go back to the main route and then enter another folder to load this other PHP file but it's not working what could be causing this issue.
ERRORS:
Warning: require_once(../PHPMailer/PHPMailerAutoload.php): failed to open stream: No such file or directory in things/public_html/classes/Mail.php on line 3
Fatal error: require_once(): Failed opening required '../PHPMailer/PHPMailerAutoload.php' (include_path='.:/opt/alt/php71/usr/share/pear') in things/public_html/classes/Mail.php on line 3
DIRECTORY STRUCTURE:
File where the requiere once is:
/public_html/classes/filethatwantstoacces.php
File where it wants to get:
/public_html/PHPMailer/PHPMailerAutoload.php
require_once('../PHPMailer/PHPMailerAutoload.php');
What you should be using is the $_SERVER['DOCUMENT_ROOT'] variable. Please read this answer to another question for details.
If you are using PHP you should get into a habit of NOT using relative file paths at all but to use absolute paths, which will guarentee to succeed every time (As long as the target file exists and is reachable, etc.).
so; use $_SERVER['DOCUMENT_ROOT']
As a side note, you do not need to use brackets for your includes/requires, it's simply giving the server more work to do for no extra benefit.
The $_SERVER['DOCUMENT_ROOT'] is the base directory of your PHP/web application, typically the contents of the folder /public_html.
Using correct syntax and the above $_SERVER value (which will point to the /public_html folder you will have:
require_once $_SERVER['DOCUMENT_ROOT'].'/PHPMailer/PHPMailerAutoload.php';
This will work from any script within your directory structure, if the file (PHPMailerAutoload.php) exists and is reachable at that given location
Given your location
/public_html/classes/filethatwantstoacces.php
doing ../ gives you
/public_html/classes
so ../PHPMailer/PHPMailerAutoload.php evaluates to
/public_html/classes/PHPMailer/PHPMailerAutoload.php
As #Martin has pointed out, using $_SERVER['DOCUMENT_ROOT'] to construct an absolute path to your file is the easiest way to avoid relative directory navigation errors such as this:
require_once $_SERVER['DOCUMENT_ROOT'].'/PHPMailer/PHPMailerAutoload.php';

PHP is looking for a file in the wrong place

I am an amateur web developer and I am trying to get my site live for the first time. The site is working and all of the files are uploaded but the site is not loading my PHP includes.
Here is the error message:
Warning: include(includes/header.php) [function.include]: failed to open stream: No such file or directory in /home4/myUsername/public_html/index.php on line 3
How can I get PHP to look in public_html/ rather than public_html/index.php?
EDIT: I have tried editing the include path. It doesn't seem to change where php is looking for the file. Additionally my includes work properly in localhost.
I'm going to assume this is your folder structure:
public_html/index.php
public_html/includes/header.php
Generally (not always), $_SERVER['DOCUMENT_ROOT'] will now reflect the path to the base public_html directory (this I'm assuming based on the context of your message). This means you can always point to the root this way. - no matter if you have /index.php or /my/deep/file/structure.php
Try this with your include statement on index.php
<?php
include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');
You may need to change the include path in your php.ini file or use set_include_path() to change the include path.
Here is the manual entry for the function call if you'd like to read more about it.
Have you checked already the include file?
in given. include(folder_includes/file_header.php);

Web application not finding file in what appears to be the correct path

I tried to reorganise my facebook application files into better folders and now when I try to load my application on facebook it throws the following error:
Warning: require_once(../scripts/mysql_connect.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\<root folder>\Model\Database.php on line 3
Fatal error: require_once() [function.require]: Failed opening required '../scripts/mysql_connect.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\<root folder>\Model\Database.php on line 3
The second error is a result of the failure of the first one I think. The weird thing is that my program works perfectly fine when I'm accessing through the localhost url in the browser but when I run it through facebook it throws this error.
In my root folder I have a "Model" folder where the Database.php file is kept and a "scripts" folder where the mysql_connect.php file is kept. I have tried clearing my cache on the browser and using private browsing but it is still throwing this error.
Does anyone know what could be wrong?
EDIT: Sorry this does not seem to be working in localhost either now! One thing I think is weird is that it says "failed to open stream : NO SUCH FILE OR DIRECTORY IN" and then lists the database.php path. Why is it looking in there?
I use the line require_once('../scripts/mysql_connect.php'); at the top of my Database.php file to include it.
It seems that on the server there is a different working directory. Something like the following owuld be a quick fix
dirname(__FILE__) . '/../scripts/mysql_connect.php'
Ok I've fixed this, but I'm still unsure why it was a problem. In my root folder I have two folders: scripts, and Model. I have a database.php file in my Model folder which has the following line of code in:
require_once('../scripts/mysql_connect.php');
For some reason this did not work, but by replacing the line with:
require_once('/scripts/mysql_connect.php');
This started working again! Just thought I would post the solution. Does anyone know why the other way failed? I thought the ".." just makes it go up one level in the folder hierarchy i.e. to the root folder in this case, and then follow the path which would have taken it to the file...
EDIT: This appears to only have solved it for localhost and not through Facebook...
Do you have permission to edit your php.ini file? One solution would be to find the line with the include path (you'll notice it has C:\xampp\php\PEAR in there already). Include the full path to the "scripts" folder you're referencing, then you can change the php code to read:
require_once('mysql_connect.php');
PHP will be able to find this file since it's in the include path. Just make sure that if you start adding several include paths that you shouldn't have a file named mysql_connect.php in two or more of the different include paths because you'll most likely get errors. Hope this helps. It definitely makes for some cleaner code.

Include statement in php file

I have a php file (php1.php). Within that php file i have the following line:
include('php/PROTECT/login.php')
However when i load the page i get the following error:
Warning: include(php/login.php) [function.include]: failed to open stream: No such file or directory
it just totally ignores the /PROTECT/ section?
Does anyone have any ideas why this is and how i can resolve the issue?
My file structure is as follows: (php1.php is within /php and login.php is within /php/PROTECT
It should look like:
include('php/PROTECT/login.php');
Make absolutely sure that that's the include call that's throwing the error. Make sure that no other code, in php1.php or in any file it has included or required tries to include php/login.php.
If php1.php is within /php/ (which I understand it to be), then you will need to use the following:
include('PROTECT/login.php');
Includes in includes can be a bit messy, but if you concatenate with DIR it is easier. DIR is always path to the file it self, if you use DIR you can always use the relative path. Like this:
include DIR . "/PROTECT/login.php";
As you can see by the error message:
Warning: include(php/login.php)
"PROTECT" is excluded from the path, probably for being in all caps.
Change the directory to all lowercase ("protect" or similar) and see if you get the same error.

Warning and Fatal error calling require_once()

I want to fetch div element from other website .
on which iam having my profile, i have tried using this code.
require_once('../simple_html_dom.php');
$html=file_get_html('http://www.example.com');
$ret=$html->find("div[id=frame-gallery]");
$ret=array_shift($ret);
echo($ret);
but this code is giving errors
Warning:
require_once(../simple_html_dom.php)
[function.require-once]: failed to
open stream: No such file or directory
in
E:\wamp\www\in.com\components\com_content\view.php
on line 22
Fatal error: require_once()
[function.require]: Failed opening
required '../simple_html_dom.php'
(include_path='.;./includes;./pear')
in
E:\wamp\www\in.com\components\com_content\view.php
on line 22
iam stuck with this plz help me with the code snippets for fetching the specific div element from a website
The file simple_html_dom.php is not where you're telling PHP to look for it.
require_once('../simple_html_dom.php');
To be safe, try using the full path instead of a relative path.
require_once('E:\wamp\www\in.com\components\simple_html_dom.php');
BTW, if the full path above is incorrect, then that is your problem. This is the path that PHP is trying.
To clarify: I'm only suggesting the OP switch to absolute paths to identify and confirm the source of the issue. Going to production with absolute paths is rarely a good idea.
require and include paths can be tricky in PHP. Try to use full paths when you can. You'll find $_SERVER['DOCUMENT_ROOT'] usefull for that.
Your inlude_path should contain ".", which means current directory.
But if you having troubles with including file by relative name, then just try to use absolute names, like require_once('E:\wamp\www\in.com\components\simple_html_dom.php');
But better it should be:
require_once 'E:/wamp/www/in.com/components/simple_html_dom.php';

Categories