JustGotAQuestion Posted April 6, 2008 Share Posted April 6, 2008 So say i have some template images in site_root/images. I have a template header page and a template footer page which basically grab images and make them form the template. Whenever i want to make a new page, i write the content, include the template header up top, and include the footer down below. But, this page i just made could be anywhere. So, i want the template header/footer's images to be linked so that no matter where the page is created, it will find the site_root/images folder to grab the images. Kind of confusing. First, am i being clear enough? Second, can anyone help? Quote Link to comment Share on other sites More sharing options...
quiettech Posted April 6, 2008 Share Posted April 6, 2008 Use the absolute path of your images. http://www.ibdhost.com/help/path/ Quote Link to comment Share on other sites More sharing options...
JustGotAQuestion Posted April 6, 2008 Author Share Posted April 6, 2008 But isnt there something i can do like $_SERVER or something to find the root of the site, and then do /images/img.gif? So like: $root = $_SERVER_ROOT (or whatever the command is) <img src="$root/images/img.gif" /> So no matter where this image is being called from, it will find the root, find the images folder, find the image. Would this work? Is there a command for something like this? Is there a better way to do it? Quote Link to comment Share on other sites More sharing options...
quiettech Posted April 6, 2008 Share Posted April 6, 2008 But isnt there something i can do like $_SERVER or something to find the root of the site, and then do /images/img.gif? That is all you need. A document's root is "./" It points to the root of the website where the document resides. if you do "./images/img.gif" you are accessing img.gif through an absolute path. If however you want to access it from other web roots (websites), you must include the fully qualified address (URI). "http://www.something.com/images/img.gif". This is also an absolute path. Quote Link to comment Share on other sites More sharing options...
JustGotAQuestion Posted April 6, 2008 Author Share Posted April 6, 2008 Oh wow. I was thinking too complicated. So if i just add the whole url (http://www.etc.com/images/img.gif) it will link correctly from anywhere. Thanks for helping me figure this out. Quote Link to comment Share on other sites More sharing options...
JustGotAQuestion Posted April 6, 2008 Author Share Posted April 6, 2008 As a side note, how does phpnuke or phpbb do this? They have images everywhere and files grabbing images from every place imaginable. They dont go through and change every link so that it has the right amount of ././ in it, do they? Quote Link to comment Share on other sites More sharing options...
quiettech Posted April 6, 2008 Share Posted April 6, 2008 I don't think you understood it yet... Let's say your site is http://www.your.com This website tree is as follows: ./ images img.gif includes incs inc.php inc2.php index.php index.php resides on the root as does the 'images' folder and 'includes' folder. When someone types www.your.com, they will be reading your root, "./" and index.php will be loaded into the browser. Now... inside inc.php you want to access img.gif. You can do this 2 ways: Relative Path ../../images/img.gif Absolute Path ./images/img.gif Quote Link to comment Share on other sites More sharing options...
JustGotAQuestion Posted April 6, 2008 Author Share Posted April 6, 2008 Ok, but if i were to use that method, then i couldn't have the ../../ or ./ paths in a header or footer file which is called from other files. The reason being that the "other files" will be in different places. Right? I can only use ../../ or ./ if i know exactly where the image is because then i can count back directories and add the right amount of ../'s. If i don't know where the file is (like if its everywhere since i am including the header and footer everywhere) then i can't use that way. These are my thoughts, i'm no expert. What am i missing? Quote Link to comment Share on other sites More sharing options...
quiettech Posted April 6, 2008 Share Posted April 6, 2008 These are my thoughts, i'm no expert. What am i missing? Read carefully that link I provided in the beginning. An absolute path maps the file to its absolute position in the directory hierarchy. That is the file position. Period. You can use it from anywhere. It never changes. A relative path maps the file to its position in relation to the document at hand. It changes depending where the document is located. So, because you want to link to the file from a document that is going to be included on different places in your directory hierarchy, you use the absolute path. Just do it. Quote Link to comment Share on other sites More sharing options...
JustGotAQuestion Posted April 6, 2008 Author Share Posted April 6, 2008 Haha, alright well i still don't fully understand, but i'm going to "just do it" and see what happens. Quote Link to comment Share on other sites More sharing options...
JustGotAQuestion Posted April 6, 2008 Author Share Posted April 6, 2008 I'm going to kill myself, this is ridiculous. Ok...let me explain exactly what i'm doing. here are the files: www.site.com/index.php (include 'template/header.php') www.site.com/test/test.php (include '../template/header.php') www.site.com/tempate/header.php (<img src="./images/img.gif" />) www.site.com/images/img.gif Ok, so i explained, very simply, what is going on in each file. Why doesn't the image show up in both files (index.php and test.php) where header.php is being included? I think its because the directory is wrong. Did i use the ./ wrong in the img src? I am using this example to demonstrate how the files will be all over calling the same header file which needs to be able to link to the image. Quote Link to comment Share on other sites More sharing options...
JustGotAQuestion Posted April 6, 2008 Author Share Posted April 6, 2008 Breakthrough: I finally got it. I wish i had known this years ago... All i had to do was <img src="/images/img.gif" />. Thats it...now it works from anywhere. This is amazing, thanks quiettech! 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.