Jump to content

Using include with files in subfolders that have subfolders


wjsullivan

Recommended Posts

This is probably really easy but it's driving me nuts.  I'm working on a classic car club website where I'm using php to replace frames.  Index.php changes the main portion of a table based on a variable set within the URL path.  One of the possible selections is a sales section.  Within the sales section we have breakdowns by car manufacturer (Ford, Pontiac, Chevy, etc.).  For each car there is a specific page and a subfolder with images of that car. 

 

Example

Index.php

About_Us.html

Join.html

Sales.html

Sales/Ford.html

Sales/Chevy.html

Sales/Chevy/1962_C1_62R0062.html

Sales/Chevy/1962_C1_62R0062_images/engine.jpg

 

Sales/Chevy/1962_C1_62R0062_images/engine.jpg shown on Sales/Chevy/1962_C1_62R0062.html.  However, if I configure index.php to include Sales/Chevy/1962_C1_62R0062.html in the main frame none of the images display.  It appears that IE thinks the path should be 1962_C1_62R0062_images/engine.jpg not

Sales/Chevy/1962_C1_62R0062_images/engine.jpg. 

 

What am I missing to get the subfolders included properly so images display?

 

Link to comment
Share on other sites

An easy way to get past this is to use full paths like this:

 

website.com/Sales/Chevy.html

 

How will that impact my ability to use something like Expressions or Dreamweaver to develop the Sales/Chevy/1962_C1_62R0062.html page?  Will all the images appear broken?

 

Link to comment
Share on other sites

You are using relative paths in your code for the images. The browser takes the current URL and appends the path you have in the code to arrive at the full URL it uses to request the image.

 

When you include that code in a page at a different path, the URL that the browser forms to request the image is no longer correct.

 

The best solution is to use paths relative to your domain root (a leading /) rather than to use paths relative to the page the code is in -

 

/Sales/Chevy/1962_C1_62R0062_images/engine.jpg

 

The above link to the image will work no matter what page it is on.

Link to comment
Share on other sites

OK so I edit Sales/Chevy/1962_C1_62R0062.html and change all the image paths from 1962_C1_62R0062_images/ to Sales/Chevy/1962_C1_62R0062_images/.  On the published site this solves the problem.  However, in my editor (both Dreamweaver and Expressions) the images are no longer appear because the path is broken.

 

I guess this isn't a major deal since the pictures don't get updated once the car is added, so I could get all the pictures up, then do a replace to change out the path and post the files.  I'd really like a way to get this to do both.

 

 

Link to comment
Share on other sites

For the case where it works on the live server (without a leading / in the code), what does the "view source" in the browser of an image link show?

 

And what does the "view source" show on the live server where it does not work with a leading / in the code?

 

And what is your code that is "including" these pages in your main page?

Link to comment
Share on other sites

OK, I think I've got the slash/no slash thing figured out.  Right now everything is being done within a subfolder of another site until we cut over.  So leading slash cut out the subfolder from the relative path.  Obviously I'll need the leading slash when I get outside the subfolder.

No slash image link = MainURL/subfolder/sales/Chevy/62R0062/62GREENCORVETTE001sm.jpg

Slash image link = MainURL/sales/C1/62R0062/62GREENCORVETTE001sm.jpg

 

The include code is very basic just "include ('sales/Chevy/1962_C1_62R0062.html');" nested in a case statement that is part of a table being echo'd.

 

The relative path is still broken within Dreamweaver and Expressions.

 

 

Link to comment
Share on other sites

Attempting to have pages at one path and also include() them at a different path requires that you use an absolute path for the image files. Since the absolute path is a variable between your current setup and the final setup, you need to use a global configuration setting that holds the part of the path that will change. Use either a variable or a defined constant to hold the value and use it in the code when you form the link for the images.

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.