I am trying to use this:
include_once("PoliticalForum/StoredProcedure/User/number_login_attempts.php");
Warning: include_once(../../untitled/sanitize_string.php) [function.include-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\PoliticalForum\StoredProcedure\User\number_login_attempts.php on line 3
Warning: include_once() [function.include]: Failed opening
'../../untitled/sanitize_string.php' for inclusion
(include_path='.;C:\xampp\php\PEAR') in
C:\xampp\htdocs\PoliticalForum\StoredProcedure\User\number_login_attempts.php
on line 3
and this:
include_once("/PoliticalForum/untitled/sanitize_string.php");
Warning: include_once(/PoliticalForum/untitled/sanitize_string.php) [function.include-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\PoliticalForum\StoredProcedure\User\number_login_attempts.php on line 3
Warning: include_once() [function.include]: Failed opening
'/PoliticalForum/untitled/sanitize_string.php' for inclusion
(include_path='.;C:\xampp\php\PEAR') in
C:\xampp\htdocs\PoliticalForum\StoredProcedure\User\number_login_attempts.php
on line 3
How can I import files safely without having those errors?
Pick one:
Provide a valid path (paths that start with / are absolute, otherwise they are relative).
Add the folder to the include_path.
Use class autoloading (if applicable).
You should make sure the files can be found on the include path, because these errors mean the file cannot be found by PHP.
More info about include can be found in the PHP manual: http://php.net/manual/en/function.include.php
I think those files you include each inlude other files (possibly with require or require_once). These files cannot be found which causes the include to fail.
Include is ignored if the file doesn't exist, but it fails if the file does exists but contains errors.
include_once("PoliticalForum/StoredProcedure/User/number_login_attempts.php");
Above statement means the directory PoliticalForum is in the same directory of the file which has this statement.
You need to look into the directory structure you are using.
Alternatively, you could use $_SERVER['DOCUMENT_ROOT'] to locate all directories starting from root directory.
ForExample:
`$_SERVER['DOCUMENT_ROOT']`/dirLevel1 // sub directory on root
Try this
include_once "PoliticalForum/StoredProcedure/User/number_login_attempts.php";
include_once"PoliticalForum/untitled/sanitize_string.php";
Related
i make MVC application (Without frameworks).
I try to include models from folder 'models' in controller, in folder controller.
include("/models/tasks_model.php");
But i get error:
Warning: include(): Failed opening '/models/tasks_model.php' for inclusion (include_path='.') in ...controller\create_task_controller.php on line 3
And
Warning: include(/models/tasks_model.php): failed to open stream: No such file or directory in ...\controller\create_task_controller.php on line 3
You need to fix your PHP paths
include("../models/tasks_model.php");
When you use this code:
include("/models/tasks_model.php");
It looks from the start of your disk because it an absolute path.
../ Goes back one folder from where your file is.
This error is quite common and it generally means it can't find the file it's looking for, but I can see the file in the directory?!
Full error:
Warning: require(/home/coinsfut/public_html/files/core.php) [function.require]: failed to open stream: No such file or directory in /home/coinsfut/public_html/new/index.php on line 4
line 4 says:
require $_SERVER['DOCUMENT_ROOT']. "/files/core.php";
the site is hosting in /new
any ideas?
Check the warning again. You are trying to include
/home/coinsfut/public_html/files/core.php
when in fact you want
/home/coinsfut/public_html/new/files/core.php
Please try
require $_SERVER['DOCUMENT_ROOT']. "/new/files/core.php";
and it should work just fine.
Alternative you could use
require "files/core.php";
to include files in a relative sub-directory since your index.php is in "new" directory.
I wrote a website in HTML but then I wanted the header and navbar portion in one file so I just had to change it once. I changed all the pages to .php and added the php includes. However now I get an error on pages that I've put in folders so I could create cruftless links.
Header file: /test/assets/header.php
Works: /test/index.php contains <?php include 'assets/header.php'; ?>
Throws Error: /test/company/index.php contains <?php include '/test/assets/header.php'; ?>
Error:
Warning: include(/test/assets/header.php) [function.include]: failed to open stream: No such file or directory
Warning: include() [function.include]: Failed opening '/test/assets/header.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear')
I am having an issue linking to the header file that is in a folder in the root folder. I believe it is a simple issue of just not knowing how to input the URL. If I attempt to include the full path to the header.php I get a URL file-access is disabled error
If you start a path with a / then it's an absolute path. Absolute mains to the actual filesystem root directory, not the virtual document root. This is why it fails.
Commonly this is what was meant:
include "$_SERVER[DOCUMENT_ROOT]/test/assets/header.php";
// Note: array key quotes only absent in double quotes context
I was also facing the same warnings:
Warning: include(/test/assets/header.php) [function.include]: failed to open stream: No such file or directory
Warning: include() [function.include]: Failed opening '/test/assets/header.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear')
I solved them with the following solution:
You have to define your path then use include function as below:
define('DOC_ROOT_PATH', $_SERVER['DOCUMENT_ROOT'].'/');
require DOC_ROOT_PATH . "../includes/pagedresults.php";
After that, you can use any directory structure.
It's not a URL; it's a filepath (although you can use full URLs when the server configuration allows it).
Super noob question here...
The file source:
www.mysite.com/blah/blah/customdir/ajax/folder/file.php
and I want to include a source:
www.mysite.com/blah/blah/customdir/include/func/functions.php
So I have tried:
require_once( '.../include/func/functions.php' );
require_once( '../include/func/functions.php' );
require_once( '././include/func/functions.php' );
and a ton of other variations. How do I get to it? Setting a top level path on every file isn't an option (that's what the function file is for...)
Each of the above is giving me an error:
Warning: include(././include/func/functions.php) [function.include]: failed to open stream: No such file or directory in /home/mysite/public_html/mysite.com/customdir/ajax/folder/index.php on line 3
Warning: include(././include/func/functions.php) [function.include]: failed to open stream: No such file or directory in /home/mysite/public_html/mysite.com/customdir/ajax/folder/index.php on line 3
Warning: include() [function.include]: Failed opening '././include/func/functions.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/mysite/public_html/mysite.com/customdir/ajax/folder/index.php on line 3
There are many ways to include a file. However, it seems you are attempting relative paths. In which case, try:
require_once '../../include/func/functions.php';
I encourage you to learn more about your options for including files. But in a nutshell, each ../ takes you back a directory. ./ represents the current directory. Otherwise, you can always use an absolute path or even (gulp) a hybrid.
Are you running under apache? use getenv("DOCUMENT_ROOT") and set your path from there.
What would be the reasons of a non working include_once?
Here's my folder hierarchy:
/Php/Controls/GridView/GridView.php
/Php/Controls/Form/Form.php
In "Form.php":
include_once '../GridView/GridView.php';
I'm getting this error:
Warning: include_once(../GridView/GridView.php) [function.include-once]: failed to open stream: No such file or directory in ...Form.php on line 4
Warning: include_once() [function.include]: Failed opening '../GridView/GridView.php' for inclusion (include_path='.;C:\php\pear') in ...Form.php on line 4
Please tell me if you want more information.
In Form.php use
include_once dirname(__FILE__) . '/../GridView/GridView.php';
This creates an absolute path, but relative to the file, where its called from.
It can't find the file.
You should use a full path, like /Php/Controls/GridView/GridView.php instead of a relative one.
Try this:
include_once './php/Controls/GridView/GridView.php';
Hope I'm not too late on this one but I thought this might be what you're looking for:
include_once realpath(dirname(__FILE__)."/../GridView/GridView.php");
Using realpath() allows you to include files even from outside your server document root directory.