gobbly2100 Posted January 6, 2007 Share Posted January 6, 2007 I am very new to PHP as I have been using HTML all my life and I have a noobish question to ask.If you want to include a file that is in a seperate directory to your root how would the include look, I currently have it like this but please correct me.<?php include("/includes/footer_links.php"); ?>It don't seem to work so anyone who can correct it I would appreciate alot thanks. Quote Link to comment https://forums.phpfreaks.com/topic/33095-noob-help/ Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Share Posted January 6, 2007 well that doesnt work me, so you could either you just type the full url from http:// or you could use the $_SERVER superglobal which i dont know much about Quote Link to comment https://forums.phpfreaks.com/topic/33095-noob-help/#findComment-154204 Share on other sites More sharing options...
taith Posted January 6, 2007 Share Posted January 6, 2007 dont use the preceding /[code]<?phprequire("includes/footer_links.php");?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33095-noob-help/#findComment-154207 Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Share Posted January 6, 2007 but what would you do if you had a file which was in [b]/members/[/b] for example. but you wanted to include [b]/includes/errors.inc.php[/b] Quote Link to comment https://forums.phpfreaks.com/topic/33095-noob-help/#findComment-154209 Share on other sites More sharing options...
psychohagis Posted January 6, 2007 Share Posted January 6, 2007 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/33095-noob-help/#findComment-154222 Share on other sites More sharing options...
gobbly2100 Posted January 6, 2007 Author Share Posted January 6, 2007 So would you suggest to use url's ALWAYS? it makes sense what you are saying. Quote Link to comment https://forums.phpfreaks.com/topic/33095-noob-help/#findComment-154233 Share on other sites More sharing options...
wildteen88 Posted January 6, 2007 Share Posted January 6, 2007 If you want to to grab a file from a directory that is higher up from where you are now use ../ to go up a directory. For example say you file structure is this:+ folder1 file1.php+ folder2 file2.phpNow you are currently in folder1 running file1.php. But you need to require file2.php 9which is in direcotry2) into file1.php what you'll want to do is this:[code]include '../folder2/file2.php[/code]That now tells PHP to go out of the current working directory and in to folder2 to get file2.phpYou should not use URLs for including files. You should try to use relative paths instead. Quote Link to comment https://forums.phpfreaks.com/topic/33095-noob-help/#findComment-154259 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.