Log in

View Full Version : About paths when including files



vividona
04-27-2009, 06:12 PM
Hi friends,

I don't know how to explain this.

I am confusing when regarding including files.

suppose I have these stuff in my script:

folder1/test1.php

folder2/test2.php

index.php

if I need to include test1.php file to be inside test2.php file, I use this function


require"../folder1/test1.php"; // (correct right???).

if I need to call test2.php to be available in index.php, I use this


require("folder2/test2.php"); // (correct right???).

but the problem it will refuse the first path which we include first.


require"../folder1/test1.php";

bcs "../" means from folder to folder

how can I make all paths readable???

X96 Web Design
04-28-2009, 12:04 AM
I'm not really getting what you're driving at...

To include a file, you use the include() function, not require...

So I think what you need to do is use:
test2.php

<?php include('../folder1/test1.php'); ?>

index.php

<?php include('folder2/test2.php'); ?>

Like that...

Is that what you're trying to do? Make test1.php show up in test2.php, and test2.php show up in index.php?

Hope that helps...

// X96 \\

borris83
04-28-2009, 04:28 AM
When you include test2.php, test2.php becomes a part of index.php... So, it executes all the lines as if it were a part of index.php...


So, code in test2.php should be


require("folder1/test1.php");

or


include("folder1/test1.php");



Require() does everything that include() does, but the only difference is, it will not execute the rest of the code if it is unable to include the file...

But this will not work if you include test2.php in another php file which is also in folder2....