Link to home
Start Free TrialLog in
Avatar of phillystyle123
phillystyle123Flag for United States of America

asked on

re: php relative paths to files using includes

i have 2 files:

index.php

and

subdirectory/index.php

both are using the same include file with relative links to say images/image.gif

can i set up some sort of configuration file in my root directory that somehow defines the a path so i don't have to make "images/image.gif" absolute in (i.e. - "http://www.mysite.com/images/image.gif"??

if so please explain thoroughly - i've never done this be for (please be gentle LOL)
Avatar of solutionDriver
solutionDriver
Flag of Germany image

Hi phillystyle123,

that's not hard to do.

Create a file config.php, and define the path to the image directory there, like:

<?php

$image_dir = "[absolute_path]/images/";

?>

Put in the absolute path instead of [absolute_path].

Then just include the config file in both index.php files:

In /index.php:

<?php

include 'config.php';

...
?>

In /subdirectory/index.php:

 <?php

include '../config.php';

...
?>

Best regards,

  sd
Avatar of phillystyle123

ASKER

hmm - i have it set up but it doesn't make sense to me - am i supposed to add that variable to each file path:

like $image_dir/bla.gif  ?

i've got this in my config file:

<?php

$image_dir = "usr/home/healthpresence/orthoneuro/images/";

?>

and then this at the top of both index.php files:

<?php include('includes/config.php');?> and <?php include(../'includes/config.php');?> but it's not working yet

ASKER CERTIFIED SOLUTION
Avatar of solutionDriver
solutionDriver
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that's funny - i'd actually already done this in a slightly different way - thanks tons - much apprecated