8

So we build websites that have to ported from local development servers, to a test server, then to a live server. For this reason we have created a variable:

<?php $path = '/_Folder_/_SubFolder_'; ?>

When we move the website from server to the next, the idea is to simply change the $path definition to retrofit to the new development server. Currently, on each page when we call an include we write:

<?php include('../_includes/_css.php'); ?>

but what I'm trying to do is to:

<?php include($path.'/_includes/_css.php'); ?>

my result I hope for is:

<?php include('/_Folder_/_SubFolder_/_includes/_css.php'); ?>

I've been failing miserably resulting in:

Warning: include(/Folder/_SubFolder_/_includes/_css.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\FREEDOM2012_FREEDOM2012_DEFAULT_\accommodations\guest-rooms.php on line 15

Other Issue I still need to include the variable source by calling "../"

<?php include('../_includes/_var.php'); ?>

if anybody has any insight into how I could do this more efficiently I would be most appreciative. Thank you very much for your time, patience and effort in responding.

Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187
Cyril Wong
  • 81
  • 1
  • 3

2 Answers2

2

Why don't you initailize your $path variable dynamically once forever and environnement-independant ?

like:

$path = dirname(__FILE__);

Starting with PHP 5.3, you have also the __DIR__ shortcut that does the same as above.

@see : http://www.php.net/manual/en/language.constants.predefined.php

Jscti
  • 14,096
  • 4
  • 62
  • 87
  • Used with `set_include_path` http://php.net/manual/en/function.set-include-path.php you can bootstrap it nicely. and have decent relative paths in your includes. – Martin Lyne Oct 25 '12 at 20:54
2

You need show the previous directory with:

<?php include('../_includes/_css.php'); ?>

Because you have ../, if your full path is css.php = /_Folder_/_SubFolder_/_includes/_css.php, then you need use this:

<?php $path = './_Folder_/_SubFolder_';
include($path.'/_includes/_css.php'); ?>

Otherwise, first show full path to file _css.php.

isherwood
  • 58,414
  • 16
  • 114
  • 157
Strannik
  • 466
  • 3
  • 6
  • 17