0

Hi. I am using this command

include ($_SERVER['DOCUMENT_ROOT']."<path>");

to import a *.php file into another *.php file.
However, i have noticed that in some cases it works, in some cases it does not. In another file I am using the same syntax to import a file which, is also importing another file into it. Is it ok to do this? Or is there a rule which says that if you import a file into another file, the which is going to be imported cannot import another file? Thank you.

6
Contributors
13
Replies
15
Views
6 Years
Discussion Span
Last Post by tomato.pgn
0

u can simply do it using this code:-

include("abc.php");

this code will simply add abc.php in another php page......
i hope this is clear.....

0

Hi. Yes, it is clear, but, in this case the file abc.php must be in the same folder with the file which is going to import it. I do not want that. I want to create a centralized folder where i am going to hold more files which are going to be included in different files which reside in different folders. So i want to include in one file, files from different folders.

Edited by alexia_net: n/a

0

What is DILE? I have given the full path along with the file name. It does not work. The file must be in the same folder. Its strange because for the file which opens the database i do not have this problem. LOL.

0

I think he means location of file with file name

Have you tried
'./abc.php' //in case reside in same folder
'./subfolder/abc.php' //in case reside in sub folder
'../upperfolder/abc.php' //in case reside in folder which one level up

Edited by urtrivedi: n/a

1
$dir = dirname(__FILE__);

$dir will have the current directory of the file. So, you can import the file you want from the current file. Here is some example.

include($dir.'../somedir/somefile.php'); //somefile.php under the somedir folder which is same root of the folder that the current php file was stored
include($dir.'somedir/somefile.php'); //somefile.php under the somedir folder which is same root of the current php file

Hope this help!

0

/includes/file_to_inc.php
/folder/secfile.php
/dir/peaches.php
primfile.php

Assume the setup. File secfile.php includes file_to_inc.php.

peaches.php and primfile.php both include secfile.php.

What path does the 'include' line in secfile.php use to include file_to_inc.php?

Is that the sort of thing you're asking?

0

Yes that sort of thing. I have not tried the solutions above, i had no time but I will give them a try. But yes, this is the type of thing i am trying.

0

Hi. There is one thing i have forgotten. The file which i want to include is not in a folder which is under the the folder in which resides the current php file, but in a different path, under the root folder. For example, if the current php file is here

RootFolder -> F1 ->F2 -> F3 - current.pfp file

the file I want to import resides here

RootFolder -> F1 -> F6 -> F7 - fileToImport.php

Also I want to transfer a value to the file which is being imported, because it will display a report. Usually , the value is being transferred like this

<a href="fileToImport.php?variable=<?php echo "value";?>"

How will the line above look like if the file resides in the location i have mentioned earlier. I do not think that any changes should be done since the file is being imported, but just for asking.

Regarding the import, i have tried to import the file as following

include('/F1/F2/F3/fileToIport.php');
and i get this error
Warning: include() [function.include]: Failed opening '/F1/F2/F3/fileToIport.php' for inclusion (include_path='.;C:\php5\pear') in C:\www\F1\F6\F7\currentFile.php' on line 265.
The line 265 is where I import the file.


if I import the file using this
include ($_SERVER.('/F1/F2/F3/fileToIport.php');
I get an error about the value I am trying to transfer
Undefined index: deviceName in C:\www\F1\F6\F7\fileToImport.php on line 21.
The line 21 contains the variable which receives the value.

In both cases, when i click the link, the page is not displayed.


Thank you.

0

Let's try going about this a little differently. If you have a good idea of where the php files are located that you will use, why not add their directories to the include path? You can follow this link to see how you can add folders to the default path for the duration of your script.

Hope this helps. :)

0

In other words, How do i transfer a value into a file which resides in a different folder?

0

Ok I have found out. The /../.. is the root and then I have to put the path to the file. Thank you.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.