Jump to content

Incorrect file paths


gwh

Recommended Posts

Hi everyone,

 

I have a page that's in a directory called 'business' that sits in the root directory of my site, ie.

 

mysite.com/business/home.php

 

This page (home.php) contains the following links in a common sidebar menu that exists on all pages of the site. The links point to a controller file called index.php which is located 2 directories within the 'business' directory:

 

<div><a href="catalogue/corporate/index.php?subcatID=1&itemTypeID=1"> Knitwear </a></div>

<div><a href="catalogue/corporate/index.php?subcatID=1&itemTypeID=2"> Shoes </a></div>

<div><a href="catalogue/corporate/index.php?subcatID=1&itemTypeID=3"> T-shirts </a></div>

 

So this controller file (index.php) is in a folder called corporate which is nested in a folder called catalogue which sits in the business directory (ie. the directory that holds home.php).

 

If I click on say the "Knitwear" link, it will parse the code in index.php and then load an include file that will display the correct information for a slideshow (based on the variable values in the url string of the links). So the following code will load the slideshow template file:

 

include 'catalogue.php';

      exit();

 

The problem is that since the template file was loaded from the controller file (index.php), it's now located in a different directory and therefore if I click on any other link (which are available in the sidebar menu) the path no longer works. So if I click on say 'T-shirts' from this point, I get a page not found error.

 

I tried changing the links to the following by putting in a forward slash:

 

<div><a href="/catalogue/corporate/index.php?subcatID=1&itemTypeID=1"> Knitwear </a></div>

 

but this didn't work. When I load home.php and then click on one of the links to go to the controller page, the address isn't complete so I get a page not found error. The following is what it loads:

 

http://localhost:8888/catalogue/corporate/index.php?subcatID=1&itemTypeID=1

 

So it's missing the 'mysite' part and also the directory called 'business'. When testing locally It should be:

 

http://localhost:8888//mysite/business/catalogue/corporate/index.php?subcatID=1&itemTypeID=1

 

I don't know how to solve this and wondered if anyone has any advice/workarounds?

 

Appreciate any help.

 

Link to comment
https://forums.phpfreaks.com/topic/193255-incorrect-file-paths/
Share on other sites

make a config.php file

include it at the start of each and every page that uses links

 

in the config.php file

<?php
$path='home/mysite/public_html/';
$path_business="$path/business/
$path_includes='home/mysite/public_html/includes';
$url='http://myDomain.com';
$url_business="$url/business";
$url_images="$url/images";
//and whatever else you end uo needing to make it easier.
?>

 

Now when you build a link do it like so:

echo "<a href=\"$url_business/catalogue/blah/blah\">link</a>

 

 

HTH

Teamtomic

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.