My php files were working fine but today when i check them i get following errors.
Warning: require_once(Connections/deal.php) [function.require-once]: failed to open stream: No such file or directory in C:\complete project\ordering system\orderingcart.php on line 1
Fatal error: require_once() [function.require]: Failed opening required 'Connections/orders.php' (include_path='.;C:\php\pear') in C:\complete project\orderingcart.php on line 1
I don't know how to resolve these errors, where do I start?
It means, the path you gave in require_once() is invalid. You have two options,
1.Checkout whether the path Connections/deal.php is correct or not. Do you have a folder Connections in the folder where this running file is placed? Is there a deal.php inside that folder Connections?
I think your running file path is C:\complete project\ordering system\orderingcart.php. It does not have such a folder and file. So place your Connections folder in C:\complete project\ordering system\ and checkout.
2.Else, You can run the page without fatal error if you change the line to include_once(Connections/deal.php). Functions assosciated with deal.php will be inactivated.
This sounds like the file has either moved OR the file permission have been altered as to prevent the server account (usually www-data) from having access to it.
You might also have better luck by trying to access the file by suppling an absolute path, rather than a relative path, e.g:
<?php
$lines = file("C:\\Documents and Settings\\myfile.txt");
foreach($lines as $line){
echo($line);
}
?>
This file path issue give full file location like
if it is windows
require_once('C:/complete project/Connections/deal.php');
For reference
http://php.net/manual/en/function.realpath.php
Related
May I ask a dumb question? I have already checked the answers for the same error such as. PHP - Failed to open stream : No such file or directory. and couple of others.
However, this one seems more elmentary problem. I am using XAMPP and I have checked the the property of csv file and it says the location. C:\xampp\htdocs
Then, I checked http://localhost/Untitled-2.php and it reutrns:
Warning: file(Book 1.csv 1): failed to open stream: No such file or directory in C:\xampp\htdocs\Untitled-2.php on line 2
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\Untitled-2.php on line 3
Why am I getting these error? My code is the following script:
<?php
$read = file("Book 1.csv 1");
foreach($read as $line){
echo $line .",";
}
?>
So, I think you have a problem with relative and absolute paths.
file("foo.bar") will try to open the file foo.bar relative to your current path. If you ran your php script from the command line, it will try to open the file in the directory you were in when you ran php.
So if you have the following directory structure:
/foo/
/foo/test.php
/foo/bar.csv
/bar.txt
And you are running php from your root directory:
/ $ php /foo/test.php
The working directory of your file will be /, even though the php file itself was in /foo. So if you do
file('bar.csv');
What php will try to open is in fact /bar.csv which doesn't exist.
Please note that what will be the relative working directory of your script can greatly differ in how your script were ran. If it is running from php-fpm mode, it will depend on your config.
To test what your current working directory is, do
echo getcwd();
And then you can list the contents of your working directory with
$files = glob(getcwd() . DIRECTORY_SEPARATOR, GLOB_NOSORT);
var_dump($files);
Or you could do something similar with readdir
All in all, I think you should try to avoid using relative file paths, as it can open up all sorts of problems. If possible, try to use absolute paths instead, like:
file('/var/www/file.csv');
I'm assuming your filename is Book 1.csv because it makes more sense. Your code might have a typo, as the file source is currently Book 1.csv 1 and this could be the cause of your problem.
Try this:
$read = file("Book 1.csv");
I have uploaded all my files in var/www/html and in one of my php files I have this line :
require_once('libraries/stripe/init.php');
the structure of my folders are list this:
www
-html/
-libraries
-> Stripe -> init.php
-register.php
I keep getting this error message:
Warning: require_once(libraries/Stripe/init.php): failed to open stream: No such file or directory in /var/www/html/register.php on line 116
Fatal error: require_once(): Failed opening required 'libraries/Stripe/init.php' (include_path='.:/usr/share/php:/var/www/html/') in /var/www/html/register.php on line 116
my php.ini file used to be like this
include_path= ".:/usr/local/php/pear/"
but based on some answers here i changed it to
include_path='.:/usr/share/php:/var/www/html/'
but it's not working!
Edit: in my libraries folder I have file called index.php the content is:
<?php
header("Location: ../"); die();
I wouldn't leave library paths to chance like that:
require_once(__DIR__ . '/libraries/Stripe/init.php');
This would make sure you include the script using the absolute directory path of the currently running script.
Update
Failed opening required '/var/www/html/libraries/Stripe/init.php'
Well, then the file is simply not there; if this file was generated by some other tool, e.g. composer, it would need to be done again on a new server (or ideally at every deployment).
i think the problem is my Stripe folder is in "s" but I'm using capital "S". is there anyway to make not case sensitive?
File systems under Linux are case sensitive by default (not even sure whether it can be changed) as opposed to Windows. Make sure you use capitalisation consistently.
That not what you are looking for. it says that php.ini file can't find the path of the file that you specified. that's why you should use absolute path to the file
require_once "path/to/file";
I have a problem with include path in PHP.
Code:
https://github.com/kukubaczek/KukuShop/blob/master/www/panel/index.php
If i open the panel/index.php page I see this error's:
Warning: require_once(/parts/header.php): failed to open stream: No
such file or directory in /PATH/KukuShop/www/panel/index.php on line 3
Fatal error: require_once(): Failed opening required
'/parts/header.php' (include_path='/..') in
/PATH/KukuShop/www/panel/index.php on line 3
How can I fix this? Here is problem with include path.
You are using absolute references when you probably want relative file locations. Try using this instead:
require_once("../parts/header.php")
What does the directory structure look like?
The set_include_path('/..'); statement doesn't seem to make sense.
Your PHP installation can't seem to find the files.
While i try to deploy the code devloped on wamp server on the dev machine on linux ,
i get this error:
Warning: require_once(/PHP file) [function.require-once]: failed to open stream: No such file or directory in /var/www/proj/index.php on line 38
Fatal error: require_once() [function.require]: Failed opening required '/PHP file' (include_path='.:/var/www/proj:/var/www/proj/framework:') in /var/www/proj/index.php on line 38
Now the PHP file i called is in the path "/var/www/proj/framework"
You have just supplied wrong filename.
Use proper path to this PHP file
require_once("/PHP file")
is using an absolute path and looking for PHP file in the server's filesystem root directory
require_once("./PHP file")
or
require_once("PHP file")
is a relative path that would search for PHP file using the include path
Also, to necromance this thread even further, don't forget Windows doesn't care about case-sensitivity, and Unix/Linux does!
This work for me, using the magic const of PHP
require once __DIR__ . "/directory/name_file.php";
I have also faced the same problem earlier.
I found on my program that, all path was included using "\" on Windows system and linux supports "/" path separator.
Please check once that all you include path is having "/" path separator.
I am receiving this error
Warning: include(../config.php) [function.include]: failed to open stream: No such file or directory in /home/soizastu/public_html/cms/happy-api/retrieve.php on line 2
Warning: include() [function.include]: Failed opening '../config.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/soizastu/public_html/cms/happy-api/retrieve.php on line 2
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'soizastu'#'localhost' (using password: NO) in /home/soizastu/public_html/cms/happy-api/retrieve.php on line 6
Error connecting to database.
basically in the cms folder is config.php i thought include "../config.php"; would do the trick but it dosent appear so.
Try computing the absolute path and including that.
include(dirname(__FILE__)."/../config.php");
I think it's the safest bet when dealing with multiple levels of include.
Make sure that the user you're using to run your web server can read the file. For a sanity check, chmod the file to 665. If it's a Windows system, then make it so that Everyone can read the file.
This should work include('../config.php');
Just define the absolute path for the cms folder, in this case if the caller script (which you try to include the config.php) /home/soizastu/public_html/cms/happy-api/retrieve.php. Then write on top line of retrieve.php :
define('ABSPATH',dirname(dirname(__FILE__)) . '/');
and include the config.php by write :
require(ABSPATH . 'config.php');
Try this code i hope it works for me
Assume we had dbconfig.php in home directory and include that file in file that inside home like path structure.
|--admin
|--includes
|--add_dbconfig.php
|--dbconfig.php
add_dbconfig.php
enter image description hereenter image description here