Jump to content

How do you handle include files with images?


carlg

Recommended Posts

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!!

 

 

 

 

 

 

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.