unable to Include Files php using include - php

I have a page called index.php which includes a page new_display.php which again includes two pages i.e. say x.php and y.php
The include is working fine on localhost but not on my hosting! The error i am getting is :-
Warning: require(/interests/sketching/udis.php) [function.require]: failed to open stream: No such file or directory in /hermes/bosweb/web054/b548/ipg.pingcampuscom/mysql/interests/sketching/new_display.php on line 154
Fatal error: require() [function.require]: Failed opening required '/interests/sketching/udis.php' (include_path='.:/usr/local/lib/php-5.2.17/lib/php') in /hermes/bosweb/web054/b548/ipg.pingcampuscom/mysql/interests/sketching/new_display.php on line 154
The Directories are :
index.php -> localhost/mysql
new_display.php -> localhost/mysql/interests/sketching/new_display.php ( Included in index.php as /interests/sketching/new_display.php )
then in new_display x.php and y.php are included as
/interests/sketching/x.php
/interests/sketching/y.php
It works all good in localhost but gives error when i publish the pages on the Domain
Does anyone has any idea why isn't this working?

/ indicates an absolute path, meaning your script is looking in the root of the filesystem for a directory called interests.
Instead, try just removing that / at the start of your paths, or prepend $_SERVER['DOCUMENT_ROOT'] to them.

You have to make
require(interests/sketching/udis.php)
Without "/"
Because you have to point to the same folder ;).

Related

require_once show warning and fatal error but in correct dir

My web is running normally until i create index.php and show me this error messege.
Warning: require_once(../_asset/faker/vendor/fzaninotto/faker/src/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\belajar\covid_config\config.php on line 10
Fatal error: require_once(): Failed opening required '../_asset/faker/vendor/fzaninotto/faker/src/autoload.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\belajar\covid_config\config.php on line 10
This my program that maybe cause the error (index.php)
include "_config/config.php";
And this my config.php
require_once "../_asset/faker/vendor/fzaninotto/faker/src/autoload.php";
My folder tables: start from htdocs
belajar-covid-_asset
|-_config
|-auth
|-dashboard
|-index.php
On require, require_once, include and include_once statements, PHP search the source file basing on the following priority order:
The full pathname, if any (e.g. include 'c:/my_include/autoload.php';)
The include_path (in your case is C:\xampp\php\PEAR)
The calling script's own directory
The current working directory
The file you require ('../_asset/faker/vendor/fzaninotto/faker/src/autoload.php') is not in any of these locations.
See PHP manual for details

PHP require failing to open stream

I am struggling trying to figure out why my require path link is not working.
My folder setup is the following:
Main domain on server test.example.com.
public_html -> test.example.com -> PHPMailer -> PHPMailerAutoload.php
Since the main domain is test.example.com, I am putting test.example.com in the path url. I have to do this for any link on the site (it was a setup mistake, but I haven't changed it yet).
The way I am trying to access this folder is below:
require 'test.example.com/test.example.com/PHPMailer-master/PHPMailerAutoload.php';
I get the following errors:
Warning: require(test.example.com/PHPMailer-master/PHPMailerAutoload.php): failed to open stream: No such file or directory in /home/example/public_html/test.example.com/php/newsletterSend.php on line 4
Warning: require(test.example.com/test.example.com/PHPMailer-master/PHPMailerAutoload.php): failed to open stream: No such file or directory in /home/example/public_html/test.example.com/php/newsletterSend.php on line 4
Fatal error: require(): Failed opening required 'test.example.com/test.example.com/PHPMailer-master/PHPMailerAutoload.php' (include_path='.:/opt/cpanel/ea-php71/root/usr/share/pear') in /home/example/public_html/test.example.com/php/newsletterSend.php on line 4
I need the link to be an absolute path because the file will be used in different folders.
Does anyone see what I am doing wrong?
it looks like your php is in a directory above the phpMailer folder.. so i think the path would be "../PHPMailer/PHPMailerAutoload.php"
you can use absolute paths if its simpler:
/home/foo/public_html/test.example.com/PHPMailer/PHPMailerAutoload.php
or relative paths if you know where you're starting!
../PHPMailer/PHPMailerAutoload.php

Include php file

I have the following directory tree on a linux server:
/home/control-center/back-office/php/average.php
/home/control-center/front-office/db.php
db.php contains the database connection information.
When I try to execute average.php, I get the following error message:
PHP Warning: include(../../front-office/db.php): failed to open stream: No such file or directory in /home/control-center/back-office/php/average.php on line 18
PHP Warning: include(): Failed opening '../../front-office/db.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/control-center/back-office/php/average.php on line 18
Should I include something else in my script so it would work? I found a couple of similar cases on the Internet, but I haven't managed to make it work.
Try include dirname(__FILE__) . '/../../front-office/db.php';
dirname(__FILE__) returns the absolute path of the current file. This ensures that you get the correct path relative to the current file.
Your problem is often encountered when the current script was included by another script. You can check this answer which is related to what I mentioned.
How do you include these 2 pages in your avarage.php file?
if you want to include header.php in index.php page which is in "sample" folder (sample/index.php) and header.php in include/header.php, then you have to write "../" before including a directory, so that would be like:
include '../include/header.php';

Problem with including a file

i am getting this error
[28-Jan-2011 09:49:03] PHP Warning: require_once(../../includes/database.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/photo/application/php/classes/users.php on line 2
[28-Jan-2011 09:49:03] PHP Fatal error: require_once() [function.require]: Failed opening required '../../includes/database.php' (include_path='.:/Applications/MAMP/bin/php5.3/lib/php') in /Applications/MAMP/htdocs/photo/application/php/classes/users.php on line 2
The file i would like to include is in
/Applications/MAMP/htdocs/photo/application/includes/database.php
I am sure the file is there, i have checked, double checked, triple checked
This is the line 2 in users.php
require_once '../../includes/database.php';
What could be the problem
Try this at the main file (e.g. index.php)
define('BASEPATH', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR);
and then
require_once(BASEPATH.'../../includes/database.php');
Working with full paths is always a good idea.
ps: it was an example, the path might be wrong.
The default include path is relative to the calling file (. is the path).
Example dir structure:
index.php
foo.php
bar.php
/assets/foo.php
/bar.php
if your index.php calls
include 'assets/foo.php';
and one/foo.php calls
include 'bar.php';
it will be equivalent to index.php calling
include 'assets/bar.php';
If you want your includes to all come from the same context, you'll need to use a root-relative path (#yoda has a good example of this).

require wp-load.php 3 directories back

I'm trying to include a file (/wp-load.php) at the beginning of the /html/ directory. I'm trying to include it from /wp-content/themes/pw-steel-orange/index-load.php, but I always get the error message
Warning: require_once(../wp-load.php) [function.require-once]: failed to open stream: No such file or directory in /nfs/c07/h01/mnt/102799/domains/platyworld.com/html/wp-content/themes/pw-steel-orange/index-load.php on line 1
Fatal error: require_once() [function.require]: Failed opening required '../wp-load.php' (include_path='.:/usr/local/php-5.2.6-1/share/pear') in /nfs/c07/h01/mnt/102799/domains/platyworld.com/html/wp-content/themes/pw-steel-orange/index-load.php on line 1
Am I doing something wrong? I though ../ brings the includes to the beginning directory
Sorry if this is a duplicate, I couldn't find something related to this in my searches...
You can issue the following command to see where you are pulling the file from (where you are at):
// get your current working directory
echo getcwd();
Then include the file accordingly.
// file is 3 dirs back
include '../../../wp-load.php';
If you are using a framework like CodeIgniter, for instance, there will be an index.php file at the very start of your application that will be calling all other code. So you would have to include that file according to that file.
Most frameworks use something they call a BASEPATH that is the current actual full server path to the site. This may prove very useful when migrating your site to another destination.
Here is a semi-automated way to do this:
$incPath = str_replace("/wp-content/plugins/PLUGIN_NAME","",getcwd());
ini_set('include_path', $incPath);
include('wp-load.php');
Regardless though, it's still a bad idea to include wp-load.php. ( if this link is ever deleted, See that page here )

Categories