rshadarack Posted July 12, 2006 Share Posted July 12, 2006 What I have right now is:http://www.website.com/header.php - Writes the heading for every page on the siteNow I like to group similar files into folders, so I also have:http://www.website.com/folder/file1.phpAnd I would like to use the header on it, so I have the code:require("../header.php");Problem is, header.php uses relative addressing for images, such as:<img src="/images/image1.jpg">So when in file1.php, it includes header.php, header.php then looks for images in http://www.website.com/folder/images instead of http://www.website.com/images.Now changing the current working directory would solve this problem quite simply. But I can't seem to find such a function for php. Can php do this? If not, can something else? And if not, are there any other work arounds besides not using folders, using absolute address, and copying all the images to http://www.website.com/folder/images? While these would work, they aren't really good solutions. Quote Link to comment https://forums.phpfreaks.com/topic/14390-php-directories/ Share on other sites More sharing options...
brown2005 Posted July 12, 2006 Share Posted July 12, 2006 use <img src="http://www.website.com/images/image1.jpg"> and so forth Quote Link to comment https://forums.phpfreaks.com/topic/14390-php-directories/#findComment-56785 Share on other sites More sharing options...
brown2005 Posted July 12, 2006 Share Posted July 12, 2006 <img src"full url">put the full url with the http://www.mysite/ etc... where it says full url i can write it cause it shows an image thing... Quote Link to comment https://forums.phpfreaks.com/topic/14390-php-directories/#findComment-56786 Share on other sites More sharing options...
rshadarack Posted July 12, 2006 Author Share Posted July 12, 2006 I know that, I addressed in the OP. I don't like this option because if I decide to move my files around, I will have to go through pages and pages of url's, changing them all.If I have no other option, it will probably be what I will do. But I would like to know if there is a better option. Quote Link to comment https://forums.phpfreaks.com/topic/14390-php-directories/#findComment-56787 Share on other sites More sharing options...
brown2005 Posted July 12, 2006 Share Posted July 12, 2006 will u always keep them in the same directory then..?i mean... always in images somewhere... Quote Link to comment https://forums.phpfreaks.com/topic/14390-php-directories/#findComment-56788 Share on other sites More sharing options...
rshadarack Posted July 12, 2006 Author Share Posted July 12, 2006 Most likely. If I change that directory name, then I have no option but to go through my code changing all the urls. What I wish to do is make it more flexible, so if I say move the entire site into a directory, everything will still work just fine using relative addressing.As I said before, changing the current working directory would solve all my troubles. Anyone know of a way to do this through php? I can't seem to find any functions of this sort, so I'm thinking the answer is no. Quote Link to comment https://forums.phpfreaks.com/topic/14390-php-directories/#findComment-56795 Share on other sites More sharing options...
brown2005 Posted July 12, 2006 Share Posted July 12, 2006 well i dont know if this helps wat i have is a config mile and i have$images_url = "http://www.allinthissite.co.uk/images";and then<img src='".$images_url."/1.jpg'> like that...then if u move the folder to cabbages or something you can just change the $images_url = "http://www.allinthissite.co.uk/images";to$images_url = "http://www.allinthissite.co.uk/cabbages";hope this is of any help.p.s. and obviously use the include('config.php'); in all the files with images Quote Link to comment https://forums.phpfreaks.com/topic/14390-php-directories/#findComment-56801 Share on other sites More sharing options...
rshadarack Posted July 12, 2006 Author Share Posted July 12, 2006 What I didn't realize before was that my header.php script also includes another script. So if I use absolute addressing, it goes through http, and thus, all the php code is ignored (if it isn't echo'ed). So absolute addressing won't work.Another thing I could do is make it so that any file that uses header.php is always one directory below it, and thus, the addressing "../someFolder/someFile" from within header.php will always work.Edit: I never thought of doing such a thing, but keeping file address in php variables would make scripts much for flexible and easier to maintain/update. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/14390-php-directories/#findComment-56802 Share on other sites More sharing options...
brown2005 Posted July 12, 2006 Share Posted July 12, 2006 no problems glad to be of help, i use to do it all the old way and include the links in all the images then i thought about it and came up with that.. Quote Link to comment https://forums.phpfreaks.com/topic/14390-php-directories/#findComment-56805 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.