Cordyceps Posted January 4, 2010 Share Posted January 4, 2010 Hi, First I'll say that I know approximately nothing about PHP. So.. <?php include '/menu.php';?> ^ I've been using that as a way of easily applying changes to the menu, footer, etc. for all pages. It works fine on localhost (XAMMP), but when I upload all the files, I get error messages - I know this has something to do with the path because when I take out the "/" (I guess when I do that it looks in the server's root directory?), it works, but only for pages in the site's root directory (since that's where the files are). I guess my question is, is there a simple way of telling it to look in the site's root directory (not the server's - that does work, but I don't want to do it that way) for the file to include? I've tried to do it a few different ways, like <?php include $_SERVER['DOCUMENT_ROOT'] . '/menu.php';?> but nothing seems to work... I just get more or less error messages, and nothing shows up. Also, if there's an easy alternative to what I'm trying to do, feel free to mention it. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/187141-question-about-include/ Share on other sites More sharing options...
ignace Posted January 4, 2010 Share Posted January 4, 2010 There are a few ways you can do this: define('ROOT_URI', dirname(__FILE__)); include ROOT_URI . '/file.php'; Or set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__)); include 'file.php'; Quote Link to comment https://forums.phpfreaks.com/topic/187141-question-about-include/#findComment-988265 Share on other sites More sharing options...
teamatomic Posted January 4, 2010 Share Posted January 4, 2010 make a config file that has something like $path='/home/joebloe/public_html'; $url='http://domain.com'; $url_img="$url/images"; then include it into your page. include('/home/joeblow/public_html/includes/config.php'); Then you can do things like $file='text/file.txt'; file_get_contents("$path/$file"); and $img_file='this_pic.jpg'; <img src="<?php echo "$url_img/$img_file"; ?>" border=0> HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/187141-question-about-include/#findComment-988288 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.