dannyluked Posted July 21, 2009 Share Posted July 21, 2009 Hi, I am trying to include my header, footer, left and right in all my pages. These are all php documents and when I navigate to there URL (mysite.com/inc/left.php) they look fine. However, when they are included in mysite.com/index.php using the code: <?php include "inc/left.php" ?> they dont show any of the images. The images for the includes are in mysite.com/inc/img. I also must add that they are linked to the include files as img/header.png, not mysite.com/inc/img/header.png. Does this matter? So, my overall questions are; 1. Why are my images not being displayed in index.php but are in mysite.com/inc/left.php? 2. Does having images in my css as img/header.png and not mysite.com/inc/img/header.png matter? 3. How do I link to the includes from the higher directories like mysite.com/example/index.php? Thank you very much in advance! Link to comment https://forums.phpfreaks.com/topic/166865-including-files-for-a-beginner/ Share on other sites More sharing options...
nrg_alpha Posted July 21, 2009 Share Posted July 21, 2009 You're missing the semicolon at the end of your snippet. Also, have you considered using $_SERVER['DOCUMENT_ROOT']? Example: <?php include($_SERVER['DOCUMENT_ROOT'].'/inc/left.php'); ?> Link to comment https://forums.phpfreaks.com/topic/166865-including-files-for-a-beginner/#findComment-879897 Share on other sites More sharing options...
ldougherty Posted July 22, 2009 Share Posted July 22, 2009 So, my overall questions are; 1. Why are my images not being displayed in index.php but are in mysite.com/inc/left.php? The images likely do not display because the way you are referencing the images. Think of it this way, if the image is is actually in mysite.com/inc/img/myimage.jpg and you are calling the include from mysite.com then when the include is parsed it looks for images in mysite.com/img/myimage.jpg which doesn't exist. 2. Does having images in my css as img/header.png and not mysite.com/inc/img/header.png matter? Yes, you should use full paths to your images if you intend on referencing them from other directories. 3. How do I link to the includes from the higher directories like mysite.com/example/index.php? You can either use the full path or relative path, ie ../inc would bring you down a level and into the inc folder. Link to comment https://forums.phpfreaks.com/topic/166865-including-files-for-a-beginner/#findComment-879915 Share on other sites More sharing options...
dannyluked Posted July 22, 2009 Author Share Posted July 22, 2009 Thank you very much!! This works. I have resolved with the method of using inc/img/image.gif instead of the full URL as the site host is only tempory and it saves me a lot of work! Sadly I still cant link to includes from other directories. I think I worded it wrong in my other post. I want to include mysite.com/members/index.php into mysite.com/inc/left.php. what is the code for this. Also when I do this the images dont show again, but they do show in mysite.com/index.php! PS. it wont let me use full URL's to include files! Link to comment https://forums.phpfreaks.com/topic/166865-including-files-for-a-beginner/#findComment-880190 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.