I have a php file in other directory and i wanna use some data of it,but when i require_once() the file i see this error:
Fatal error: require_once(): Failed opening required '/Controller/UserController' (include_path='.;C:\php\pear') in E:\wamp\www\newmvc\index.php on line 20
newmvc is my root
and i'm sure there is no misspelling and i have the file.
$Controller="user";
$param=array();
$className=ucfirst($Controller)."Controller";
$controllerfilepath="/Controller/".$className;
require_once "$controllerfilepath";
I suppose you forgot to add an extension .php for class filename:
$controllerfilepath="/Controller/" . $className . ".php";
Related
I have [root]/includes/helpdesk/pipe.php with this code:
#!/opt/cpanel/ea-php55/root/usr/bin/php
<?php
require_once("pipeprocess.php");
In the same location in pipeprocess.php in first line I include another file still in the same location: helpdesk.php
then in [root]/includes/helpdesk/helpdesk.php in the first line I have:
require_once ("../../config.php");
config.php is in [root], this is why I have twice ../../, helpdesk.php works fine with direct access, but if run pipe.php via pipe command setup in cPanel I get a bounce error that config. php is not found:
PHP Warning: require_once(../../config.php): failed to open stream:
No such file or directory in
/home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on line
21
Warning: require_once(../../config.php): failed to open stream: No
such file or directory in
/home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on line
21 PHP Fatal error: require_once(): Failed opening required
'../../config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php')
in /home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on
line 21
Fatal error: require_once(): Failed opening required
'../../config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php')
in /home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on
line 21
Why I am getting this pipe error as direct access to helpdesk.php works fine? does pipe not accept ../ or ../../ as parth of the path? or is there an EasyApache4 issue? I did several tests and noticed this is because of ../ as part of including path. Does pipe/EasyApache4 have problem with this?
What if you used __DIR__, based on where your currently running script file's folder?
As of PHP 5.3.0, you could use something like this:
require_once (__DIR__ . "/../../config.php");
I'm having problems debugging this php error. '/app/bootstrap.php' exists so not sure why I'm getting this error? Can anyone help? Thanks
[24-Mar-2017 10:42:50 Europe/London] PHP Warning: require_once(/app/bootstrap.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/example.com/index.php on line 2
[24-Mar-2017 10:42:50 Europe/London] PHP Fatal error: require_once(): Failed opening required '/app/bootstrap.php' (include_path='.:/Applications/MAMP/bin/php/php5.6.30/lib/php') in /Applications/MAMP/htdocs/example.com/index.php on line 2
The path /app/bootstrap.php looks like a root path ( and the root isn't your website root, but your Mac root directory).
Change require path to __DIR__ . '/app/bootstrap.php', it means to require a sccript that in /app/bootstrap.php relative to CURRENT directory.
It getting following errors.
Warning: require(validation_functions.php): failed to open stream: No such file or directory in C:\xampp\htdocs\practice\validation_errors.php on line 11
Fatal error: require(): Failed opening required 'validation_functions.php' (include_path='.;c:\php\includes;') in C:\xampp\htdocs\practice\validation_errors.php on line 11
I already find the solution but not properly get it.
getcwd(); -> C:\xampp\htdocs\practice
and
echo $_SERVER["DOCUMENT_ROOT"]; -> C:/xampp/htdocs
You are not providing file name as a string to require() function.
Try like this:
require("validation_functions.php");
I have some big problems with path to my php files. I got a suggestion that I should define my path for the root. But is this define correct, or do I need something else on it?
<?php
// define path to application root
define( 'APP_ROOT', dirname(__FILE__) );
require_once( APP_ROOT . '/resources/includes/header.html' );
?>
Because I still get the same error:
Warning: require(/Applications/MAMP/htdocs/website/resources/auth/resources/includes/header.html): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/website/resources/auth/profile.php on line 4
Fatal error: require(): Failed opening required '/Applications/MAMP/htdocs/website/resources/auth/resources/includes/header.html' (include_path='.:/Applications/MAMP/bin/php/php5.6.2/lib/php') in /Applications/MAMP/htdocs/website/resources/auth/profile.php on line 4
Updated:
I'm new to PHP and I need to use some classes from an external library in my project.
My .php file, SMMain.php is in /Library/WebServer/Documents directory on my Mac. I placed the classes from the outside library right there next to it. All of these files are from the namespace Parse;. Some of the classes are in a directory called Internal.
No matter what require_once I try I get errors that the files are not found. Here's what I tried:
require_once('\Internal\Encodable.php');
produces this error:
Fatal error: require_once(): Failed opening required '\Internal\Encodable.php' (include_path='.:') in /Library/WebServer/Documents/SMMain.php on line 13
Next try:
require_once('/Internal/Encodable.php');
produces this:
Fatal error: require_once(): Failed opening required '.php' (include_path='.:') in /Library/WebServer/Documents/SMMain.php on line 7
I also tried:
require_once(realpath($_SERVER["DOCUMENT_ROOT"]) .'/Internal/Encodable.php');
Gives no error for the /Internal/Encodable file, but this produces another error:
Fatal error: Class 'ParseObject' not found in /Library/WebServer/Documents/SMMain.php on line 24
ParseObject.php is in the root directory together with my SMMain.php. So I tried requiring it like this:
require_once(realpath($_SERVER["DOCUMENT_ROOT"]) . '/ParseObject.php');
which gives this error:
Fatal error: Class 'ParseObject' not found in /Library/WebServer/Documents/SMMain.php on line 24
and if I try this:
require_once(realpath($_SERVER["DOCUMENT_ROOT"]) . 'ParseObject.php');
the error is:
Fatal error: require_once(): Failed opening required '/Library/WebServer/DocumentsParseObject.php' (include_path='.:') in /Library/WebServer/Documents/SMMain.php on line 17
So what's the solution?
Use require_once($_SERVER["DOCUMENT_ROOT"] .'/Internal/Encodable.php'); if the Internal directory is under the server document root and the Encodable.php is in there.
You can use the echo getcwd(); to see, where is the current working directory.
I am always doing that, when i call my index.php file (it handles all other files), to determinate, where is my base path, and store it in a constant. So lately, i will always include files with that path as an absolute path.