Daney11 Posted January 23, 2007 Share Posted January 23, 2007 Hi Guys,Im not sure wether or not this topic is supposed to go here or in PHP Help.Anyways, my problem is that i am creating a website and i am using top.php and bottom.php and the top and bottom of my website. Top and Bottom is my website design code etc and any other file i create will have <?include("top.php");?>New File Contents<?include("bottom.php");?>Like so.My problem is however, when i create a new folder, for example "/teams" and create files in there and add the include top and bottom.I use ../top.php and ../bottom.php and it displays the website, but without the images.Im not sure what to do or if there is an easier way of doing this?Thanks in advanced.Dane Quote Link to comment Share on other sites More sharing options...
nogray Posted January 23, 2007 Share Posted January 23, 2007 the php include file will take the code out of the top.php and place it in the other file (the files inside teams). Most like the image reference is relative to the top.php file, so when the file is included in another folder, it can't find the image. Try to use absolute pathse.g. http://www.site.com/images/image1.gif instead of images/image1.gif Quote Link to comment Share on other sites More sharing options...
Daney11 Posted January 23, 2007 Author Share Posted January 23, 2007 Thats what i thought.So is this possible, im sure it is....If i created say.... website_values.php and defined the website urldefine("website_url",'http://mywebsite.com');And then included...include("website_values.php");In all my files from now on and then use$website_url/images/image1.gif instead of images/image1.gifWould that be better? Or is there a better way of doing this?Thanks againDane Quote Link to comment Share on other sites More sharing options...
fenway Posted January 23, 2007 Share Posted January 23, 2007 Or use relative pathnames. Quote Link to comment Share on other sites More sharing options...
chronister Posted February 1, 2007 Share Posted February 1, 2007 I have had this same problem because I also use a standard header / footer design.My solution is in the header page(top.php) define [code]$root='http://'.$_SERVER['HTTP_HOST'].'/' ;[/code]Then in all your images simply call the $root var e.g. <img src=<?=$root ?>path/to/image/here.jpg >I like using $_SERVER['HTTP_HOST'] because I can design on my home machine and then upload to my production server and I don't have to change anything and everything stays absoluteYou can also define $root as [code]$root='http://www.your_site.com/';[/code]Not the BEST way, but it works the way I want it to. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 1, 2007 Share Posted February 1, 2007 or jsut use$_SERVER['DOCUMENT_ROOT'] . '/path/to/file.jpg' Quote Link to comment 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.