0

I want include file from another folder. i used different ways but nothing helped me out. One folder back solution and two folders back none gave me any positive respone.

I always getting this error

This is the tree of the folders

<?php
   include_once('./../models/config.php');
?>
4
  • models/config.php ? Commented May 10, 2017 at 7:35
  • Which version of CakePHP are you using? Commented May 10, 2017 at 7:36
  • i am using custome php Commented May 10, 2017 at 8:09
  • 'One folder back solution and two folders back'! You surely know where your file is? You should make sure you know where the script you are trying to use the include is using dirname(__FILE__) to determine how to traverse the directories and use include_once (although if the file is critical you should really use require_once instead - andy-carter.com/blog/…). Commented May 10, 2017 at 8:36

3 Answers 3

2

Include following lines of code in your file

<?php require_once('../models/config.php'); ?>
Sign up to request clarification or add additional context in comments.

5 Comments

i got these two warning 1: Warning: require_once(../models/config.php): failed to open stream: No such file or directory in C:\wamp64\www\personal-site\user\master.php on line 2..... 2: Fatal error: require_once(): Failed opening required '../models/config.php' (include_path='.;C:\php\pear') in C:\wamp64\www\personal-site\user\master.php on line 2
see just adding <?php require_once('../config.php');?>
Thanks @spirit. actually there was an error in my config file which was creating mess. Removed that error and it boom up
Congrats Bashir..if you feel above code right plz vote for me thanks..:)
yup your code is right if one need to go one step back folder and then dive in to the models folder and then access config.php file. .
1

The folder where the file is, and the file master.php are in the same folder :

<?php include_once('models/config.php'); ?>

5 Comments

This just vanish all item on the page. The master.php is in user folder and config.php is in models folder that itself is in user folder. i mean models is inside user folder too.
I am going deeper one folder
thanks @Thomas. actually there was a lil problem in my config file which was creating mess
Here is the issue! :) Don't forget to check my answer if it helped you :D
how can i, it saved my day :).
1

How about this:

require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'config.php'

Your models directory is in same path as master.php. I recommend always using absolute paths for this kind of things.

4 Comments

This also vanish all item on the page and returned an empty page with warning just. The master.php is in user folder and config.php is in models folder that itself is in user folder. i mean models is inside user folder too.
I am going deeper one folder
So I think it's work and you have an error in the PHP file you try to include. Put your include at the end of master.php, you will see the master.php content, and at the end, a php error message
Thanks @Palethorn. this worked for me. actually there was little problem in my config file which was creating mess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.