Jump to content

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


seany123
 Share

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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.