Jump to content

help with using include("../");


seany123

Recommended Posts

basically i want to be able to include a file.. in other files within  folders.

 

i have a universal include which holds my template etc and i have a include in there which mess's up when being called by a file inside a folder...

 

now i know usually you can just use.

 

include("../file.php");

 

or you can define the entire url of the included file.. but i was wondering if there was another way?

Link to comment
https://forums.phpfreaks.com/topic/212934-help-with-using-include/
Share on other sites

You could do something like this instead

include $_SERVER'[DOCUMENT_ROOT'] . '/file.php';

 

or you can define the entire url of the included file..

Includes behave differently if you're using a url to include the file. It'll only include the output of the included PHP file rather than the actual PHP code.

You could do something like this instead

include $_SERVER'[DOCUMENT_ROOT'] . '/file.php';

 

Sorry, Dont mean to intrude. Just 2 quick things.

 

I believe the above was supposed to be

 

include $_SERVER['DOCUMENT_ROOT'] . '/file.php';

 

The single quote was outside the square bracket.

 

Also, just for the record, I may be wrong here, but IMHO, it is better to use require_once than include as the script will die if something goes wrong with it. This is esspecially good when "including" a config file, template class or anything which is neccessary.

 

Best Regards,

Mantyy

You could do something like this instead

include $_SERVER'[DOCUMENT_ROOT'] . '/file.php';

 

Sorry, Dont mean to intrude. Just 2 quick things.

 

I believe the above was supposed to be

 

include $_SERVER['DOCUMENT_ROOT'] . '/file.php';

 

The single quote was outside the square bracket.

 

Also, just for the record, I may be wrong here, but IMHO, it is better to use require_once than include as the script will die if something goes wrong with it. This is esspecially good when "including" a config file, template class or anything which is neccessary.

 

Best Regards,

Mantyy

 

thankyou for your post.. i have used the code you added and it worked good.

 

the file im currently including only displays 4 tables... but because there is alot of ifs etc in the table i felt it would be less clutter to somple just include the file.. so require_once really isnt needed.

 

however i will be looking into adding require_once for my config.php and possibly my template (although im guessing template is not so important.)

 

anyway problem solved now thanks for help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.