This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
require_once () or die() not working
I try to include a file with require_once and i get:
Warning: require_once(1) [function.require-once]: failed to open stream: No such file or directory in /var/www/phpscrape/index.php on line 3
Fatal error: require_once() [function.require]: Failed opening required '1' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/phpscrape/index.php on line 3
I can do a cat /var/www/phpscrape/simplehtmldom/simple_html_dom.php which means the path is correct.
The permissions are www-data:www-data same as index.php which is executing. To be sure i also set chmod 777 but that didnt help either.
The command line is:
<? php
require_once("/var/www/phpscrape/simplehtmldom/simple_html_dom.php") or die("no such file");
You are hitting a weird side effect of the fact that require is not a real function, but a language construct.
require does not require its parameter to be wrapped into parentheses.
Therefore, what require interprets as the parameter is the full rest of the line:
(("/var/www/phpscrape/simplehtmldom/simple_html_dom.php") or die("no such file"))
which equals 1.
I would either just drop the die() (require will die on error anyway) or do a file_exists() check beforehand.
require_once("var/www/phpscrape/simplehtmldom/simple_html_dom.php") or die("no such file");
Without the / at the beginning
If not working try:
require_once("phpscrape/simplehtmldom/simple_html_dom.php") or die("no such file");
Related
I am calling the function require_once '../autoload.php'; but I get the error
Warning: require_once(../autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Api\Autotask\vendor\test.php on line 2
Fatal error: require_once(): Failed opening required '../autoload.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\Api\Autotask\vendor\test.php on line 2
What am I doing wrong?
To avoid this type of problems, and for best practice, i advice to use the root path:
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
The code above will assign to $root your realpath on the server.
After that just use the require/include etc according to your localhost/webserver root :
require_once($root/Api/Autotask/vendor/autoload.php)
For example, if your file is located in websiterootfolder/php/nice_folder
Your code will be :
require_once($root/php/nice_folder/autoload.php)
By using this practice, you can include any file from whatever position and any way you want, dynamic or not
These are the errors I have:
Warning: include(core/init.inc.php):
failed to open stream: No such file or directory in test.php on line 2
Warning: include(): Failed opening '/core/init.inc.php'
for inclusion (include_path='.;C:\php\pear') in test.php on line 2
Here is my code:
init.inc.php
<?php
$path = dirname(__FILE__);
include("{$path}/inc/csv.inc.php");
include("{$path}/inc/users.inc.php");
?>
test.php
<?php
include('/core/init.inc.php');
?>
Normally I should have at this white screen, but I got all errors immediately, anyone have any idea that this could be?
I followed this tutorial on the web: https://www.youtube.com/watch?v=TqhSrBJHTIY (3 parts)
I think I have as in the tutorial. Yet done the same:
As written in the comments, your files are not called .inc.php - they're called .inc. That means that init.inc.php in fact, does not exist, but init.inc does.
You have two options:
Rename your init.inc to init.inc.php, csv.inc to csv.inc.php and users.inc to users.inc.php
Change your include statements to use include('core/init.inc'); instead.
There may be a super easy fix to this that I am completely missing. I've looked around Stack Overflow and other answers say that what I am doing now should work.
I am trying to require a config.php so I can get the credentials to a database. I am requiring it via require_once (dirname(__FILE__) . "/../../config.php"); The file that I am referencing the method from (config.php) is located at /internal/CloudShop/login config.php is located at /internal/config.php But, when I load the page, I get this error
Warning: require_once(C:\xampp\htdocs\CloudShop\internal\CloudShop/../../config.php): failed to open stream: No such file or directory in C:\xampp\htdocs\CloudShop\internal\CloudShop\login.php on line 48
Fatal error: require_once(): Failed opening required 'C:\xampp\htdocs\CloudShop\internal\CloudShop/../../config.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\CloudShop\internal\CloudShop\login.php on line 48
What am I doing wrong?
The script where you execute require_once(...) is in /internal/CloudShop. You are looking for a file that is in /internal. Therefore you need to go only 1 directory above in the hierarchy, not two.
require_once (dirname(__FILE__) . "/../config.php");
will do the trick.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
including php file from another server with php
i want to have my own error system instead of having the php errors so for example i require a file from another server and that server is not available right now
<?php
require 'http://example.com/file.php' or die ("that host is not available right now");
?>
but instead i get
Warning: require(1) [function.require]: failed to open stream: No such
file or directory in C:\xampp\htdocs\index.php on line 5
Fatal error: require() [function.require]: Failed opening required '1'
(include_path='.;C:\xampp\php\PEAR') in
C:\xampp\htdocs\index.php on line 5
It's because require 'foo' or bar() is interpreted as require ('foo' or bar()). 'foo' or bar() equals true, i.e. 1. If you want to write it like this, use different parentheses:
(require 'http://example.com/file.php') or die ("that host is not available right now");
But, you don't need die at all here, since require will already halt program execution if the required file can't be loaded. Just require 'http://example.com/file.php'; will do fine. Whether you should actually load foreign PHP files over the network is another story (hint: probably not).
The problem is the precedence of operators. The PHP are including the result of the "or" comparison (true). Try to remove this.
include('http://...') or die('error...');
It will work.
I have encountered a problem that I have not come accross yet when setting up a log in page using php.
The page has a error message that relates to line 1 ( require_once('../Connections/Login.php)
that states
[function.require-once]: failed to open stream: No such file or directory
Fatal Error: require_once() [function.require]: failed opening required ... (include_path='.:/usr/share/pear-php5')
I know it is probably really simple and stupid, but I'm really struggling to self-troubleshoot and would really value some help please?
This is where I have been so confused. I also thought the same, that it just couldn't find the file; however the structure is just as you have said:
htdocs/comparison.php (the log in page)
htdocs/Connections/connComparisonLogin.php
Sorry this is going to confuse you, I simplified the actual script in my original question and here is the actual error message:
Warning: require_once(../Connections/connComparisonLogin.php) [function.require-once]: failed to open stream: No such file or directory in /home/fhlinux135/s/suzukigenuine.com/user/htdocs/comparison.php on line 1
Fatal error: require_once() [function.require]: Failed opening required '../Connections/connComparisonLogin.php' (include_path='.:/usr/share/pear-php5') in /home/fhlinux135/s/suzukigenuine.com/user/htdocs/comparison.php on line 1
Have I done it all wrong?
I think your require statement should be:
require_once 'Connections/connComparisonLogin.php';
Where is your "Connections/Login.php" relative to the currrent php file.
php will look for the file relative to the current file, or, in one of the directories specified in the "include_path" php.ini setting.
The error just means php can't find the Login.php file. Assuming the page you are calling is index.php you should have a director structure like
-Dir1
|-index.php
-Connections
|-Login.php
Why are you going up a directory in your require statement? Remove the "../" from the beginning of your require_once path.