I'm at my first steps in PHP and i'm trying to import a file with some functions but it is not working.
I tryed to use include, include_once, require. function.php is in the same directory.
<?php
include 'function.php';
$accounts = [ ... ];
$accounts['123.456.789-10'] = withdraw(
$accounts['123.456.789-10'],
500
);
function withdraw is in function.php file.
Warning: include(function.php): failed to open stream: No such file or
directory in banco.php on line 2
Warning: include(): Failed opening 'function.php' for inclusion
(include_path='.;C:\php\pear') in banco.php on line 2
Fatal error: Uncaught Error: Call to undefined function sacar() in
banco.php:19 Stack trace:
0 {main} thrown in banco.php on line 19
check the permissions of the file you are including and the state of letters capital or small every thing must be the same
Related
I am trying to use the library PDFparser using the composer.
I know it is installed in /home/servername/vendor/smalot/pdfparser
My php script is found in /home/servername/public_html/test.php
This is my code:
<?php
ini_set('display_errors',true);
include 'vendor/autoload.php';
$parser = new \Smalot\PdfParser\Parser();
?>
and this is the error I am getting:
Warning: include(vendor/autoload.php): failed to open stream: No such file or directory in /home/servername/public_html/test.php on line 3
Warning: include(): Failed opening 'vendor/autoload.php' for inclusion (include_path='.:/usr/share/php') in /home/servername/public_html/test.php on line 3
Fatal error: Uncaught Error: Class 'Smalot\PdfParser\Parser' not found in /home/servername/public_html/test.php:4 Stack trace: #0 {main} thrown in /home/servername/public_html/test.php on line 4
What am I doing wrong? This is my first time using a php library
I created a config file that has a variable I want to use as a constant.
<?php
$ROOT_PATH = 'C:/Users/me/Documents/app-qas.com/site';
?>
On a CLASS page where I want to use the variable I added the following before instantiating the CLASS:
include_once("config.php");
$root=$ROOT_PATH;
I made the appropriate scoping changes to the functions in my class as follows:
global $root;
include_once($root."/Library/API/database.inc.php");
When I run my app, it DOES perform all of the data connections it
is designed to do, BUT it STILL returns the following errors:
Warning: include_once(config.php): failed to open stream: No such file
or directory in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 5
Warning: include_once(): Failed opening 'config.php' for inclusion
(include_path='.;C:\php\pear') in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 5
Notice: Undefined variable: ROOT_PATH in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 6
Warning: include_once(/Library/API/database.inc.php): failed to open
stream: No such file or directory in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 112
Warning: include_once(): Failed opening
'/Library/API/database.inc.php' for inclusion
(include_path='.;C:\php\pear') in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 112
Warning: include_once(/Library/API/database.inc.php): failed to open
stream: No such file or directory in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 112
Warning: include_once(): Failed opening
'/Library/API/database.inc.php' for inclusion
(include_path='.;C:\php\pear') in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 112
If I comment out the include and hard code the $root it runs like before BUT it DOES NOT throw any errors:
#include_once("joblaunch.php");
#$root=$ROOT_PATH;
$root='C:/Users/me/Documents/app-qas.com/site';
I don't understand why it runs and throws errors when getting the variable from the config.php but runs and doesn't throw an error when hard coding the path.
if you define a constant instead of a variable, this problem should be solved,
definition
old:
$ROOT_PATH = 'C:/Users/me/Documents/app-qas.com/site';
new:
define('ROOT_PATH', 'C:/Users/me/Documents/app-qas.com/site');
usage
old:
$root=$ROOT_PATH;
new:
$root = ROOT_PATH;
I am starting to work on a site that has been up for some time. It is producing the following error messages before I even got started:
Warning: main(includes/main_functions.php) [function.main]: failed to open stream: No such file or directory in \\boswinfs01\home\users\web\b748\ez.paphospro\includes\top.php on line 22
Warning: main() [function.include]: Failed opening 'includes/main_functions.php' for inclusion (include_path='.;c:\php\4\pear') in \\boswinfs01\home\users\web\b748\ez.paphospro\includes\top.php on line 22
Warning: main(includes/functions/functions_email.php) [function.main]: failed to open stream: No such file or directory in \\boswinfs01\home\users\web\b748\ez.paphospro\includes\top.php on line 23
Warning: main() [function.include]: Failed opening 'includes/functions/functions_email.php' for inclusion (include_path='.;c:\php\4\pear') in \\boswinfs01\home\users\web\b748\ez.paphospro\includes\top.php on line 23
Fatal error: Call to undefined function: get_includes_file() in \\boswinfs01\home\users\web\b748\ez.paphospro\includes\top.php on line 24
Could it be that the path in the includes\top.php file is incorrect? Or do I need to look for something else?
the top.php file includes the following code:
define('BASE_PATH' , '/--/--/--/--/--/--/'); (I took out the path in this example).
and on the lines 22, 23, 24 it has the following code:
`include("includes/main_functions.php");
include("includes/functions/functions_email.php");
include(get_includes_file("includes/config.php"));`
all the above files are on the server in those directories.
I really need some direction as to why the errors are there and what I can do to fix them.
Thanks for any and all help or suggestions.
The warning is caused by non existing script file or wrong file permissions.
I would recommend you to do some refactoring, replacing the include function with require_once. This way you'll get a fatal E_COMPILE_ERROR level error which is better than a misleading application.
Then you must define your application base path define('DOCROOT', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR); and use it to reference all other application dependencies (e.g. require_once(DOCROOT.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR.'main_functions.php');
Hi i have the following directory structure:
Main Folder -> Classes -> user_classes
all nested in each other. I have the Following files inside Classes directory
always_include_top.php
custom_error_handler.php
config.php
database.php
Out of which the database.php file is as follows:
<?php
include_once("always_include_top.php");
include_once("config.php");
include_once("custom_error_handler.php");
include_once ("user_classes/newDatabase.php");
class Database extends newDatabase
{
// some more code... with extra functions
public function dbBackUp($backupfile = NULL)
{
//code...
}
}
?>
I have the Following file at User user_classes directory
newDatabase.php
The code sample for this file is
<?php
include_once("../always_include_top.php");
include_once("../config.php");
include_once("../custom_error_handler.php");
error_reporting(E_ALL);
class newDatabase
{
// my code goes here
}
?>
Why do i get the following error in classes/database.php ( No error in classes/user_classes/newDatabase.php )
Warning: include_once(../always_include_top.php)
[function.include-once]: failed to open stream: No such file or
directory in
E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on
line 2
Warning: include_once() [function.include]: Failed opening
'../always_include_top.php' for inclusion
(include_path='.;C:\php\pear') in
E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on
line 2
Warning: include_once(../config.php) [function.include-once]: failed
to open stream: No such file or directory in
E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on
line 4
Warning: include_once() [function.include]: Failed opening
'../config.php' for inclusion (include_path='.;C:\php\pear') in
E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on
line 4
Warning: include_once(../custom_error_handler.php)
[function.include-once]: failed to open stream: No such file or
directory in
E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on
line 5
Warning: include_once() [function.include]: Failed opening
'../custom_error_handler.php' for inclusion
(include_path='.;C:\php\pear') in
E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on
line 5
Fatal error: Cannot redeclare class Database in
E:\wamp\www\greeting_cards\adm\classes\database.php on line 12
I want both files to individually compile. As i would be including the files in other files based on page types. Whats the problem with including here?
When you use include_once(), it doesn't change to the directory where a particular file is located and execute it there, it executes the contents of that file within the context of the current file. So, classes/user_classes/database.php is executed as if it were in the classes folder. ".." refers to the Main folder in that case, so it's looking for the first three files in the Main folder. Those files aren't in the Main folder, so it gives you the warnings.
I am running a script from
/wp-content/themes/currenttheme/chat.php
I want to include in the above php another one located in
/forum/chat/index.php
The index.php includes its own files
I already tried
$root = $_SERVER['DOCUMENT_ROOT'];
include($root."/forum/chat/index.php");
but I get this error
Warning: require(D:/My Dropbox/xampp/htdocs/lib/custom.php) [function.require]: failed to open stream: No such file or directory in D:\My Dropbox\xampp\htdocs\forum\chat\index.php on line 17
Fatal error: require() [function.require]: Failed opening required 'D:/My Dropbox/xampp/htdocs/lib/custom.php' (include_path='.;\My Dropbox\xampp\php\PEAR') in D:\My Dropbox\xampp\htdocs\forum\chat\index.php on line 17
(the index.php also includes some files, but the /forum/chat is ommited somehow in the path)
then I tried
$path = getcwd();
$myfile = "/forum/chat/index.php";
include ($path.$myfile);
and got this error:
Warning: include(D:\My Dropbox\xampp\htdocs\forum/forum/chat/index.php) [function.include]: failed to open stream: No such file or directory in D:\My Dropbox\xampp\htdocs\wp-content\themes\currenttheme\chat.php on line 24
Warning: include() [function.include]: Failed opening 'D:\My Dropbox\xampp\htdocs\forum/forum/chat/index.php' for inclusion (include_path='.;\My Dropbox\xampp\php\PEAR') in D:\My Dropbox\xampp\htdocs\wp-content\themes\currenttheme\chat.php on line 24
There is no problem with index.php. It is being included.
The error message says about custom.php file
Just use the same $_SERVER['DOCUMENT_ROOT'] technique for the custom.php
you have to add /forum/chat manually as there is no path to be omitted
Something wrong with:
include('../../../forum/chat/index.php');
?
There are all sorts of reasons why the code you've published will fail.
C.
use this.
require_once(ABSPATH.'forum/chat/index.php');
here ABSPATH = WordPress physical root directory path with trailing slash