carlg Posted February 26, 2008 Share Posted February 26, 2008 I have a directory structure which kind of resembles the following: $DOCROOT/includes $DOCROOT/myproducts $DOCROOT/images There is a file called banner.php in the includes folder which is actually the banner of every page of my site. It uses an image which is stored in the images subfolder. Every file in my site uses banner.php including index.php which is in $DOCROOT. Files in the myproducts directory also include banner.php. The problem is that since the products subfolder and index.php are different locations, the path for the image changes. How do you solve this problem? I know I could use absolute paths (Put the http:// in front of the img path, but what if I want to move the site from server to server easily, for testing purposes.) Thanks for the info!! Link to comment https://forums.phpfreaks.com/topic/93005-how-do-you-handle-include-files-with-images/ Share on other sites More sharing options...
carlg Posted February 26, 2008 Author Share Posted February 26, 2008 OK, I think I found a good solution. I'll post it here in case someone is following this thread. I created a global php variable called $localroot. Let's say I'm running the site from www.example.com, I change $localroot to equal http://www.example.com If I want to run the site at www.myexample.com I chane $localroot to equal http://myexample.com This way I cold move the site and it's structure anywhere I want and all I need to do is change the $localroot variable. Link to comment https://forums.phpfreaks.com/topic/93005-how-do-you-handle-include-files-with-images/#findComment-476503 Share on other sites More sharing options...
DarkerAngel Posted February 26, 2008 Share Posted February 26, 2008 or you could always try $localroot = "http://".$_SERVER["SERVER_NAME"]; Link to comment https://forums.phpfreaks.com/topic/93005-how-do-you-handle-include-files-with-images/#findComment-476507 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.