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

 

 

 

 

 

 

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.