seany123 Posted September 9, 2010 Share Posted September 9, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/212934-help-with-using-include/ Share on other sites More sharing options...
JasonLewis Posted September 9, 2010 Share Posted September 9, 2010 You need to define an absolute path that is available to your files, that way you can just use the absolute path for the include instead of relative paths. Quote Link to comment https://forums.phpfreaks.com/topic/212934-help-with-using-include/#findComment-1109078 Share on other sites More sharing options...
wildteen88 Posted September 9, 2010 Share Posted September 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/212934-help-with-using-include/#findComment-1109116 Share on other sites More sharing options...
DarkMantis Posted September 9, 2010 Share Posted September 9, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/212934-help-with-using-include/#findComment-1109127 Share on other sites More sharing options...
seany123 Posted September 9, 2010 Author Share Posted September 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/212934-help-with-using-include/#findComment-1109318 Share on other sites More sharing options...
DarkMantis Posted September 12, 2010 Share Posted September 12, 2010 No Problem. Glad I could help and happy that you got it sorted now Quote Link to comment https://forums.phpfreaks.com/topic/212934-help-with-using-include/#findComment-1110263 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.