Testing a directory?

I’m trying to run a php script only if iim currently in 1 of 2 directories, so this is what I came up wit


<?php 
if (getcwd() == "recreation" || getcwd() == "service"  ) {
$CSS=1; require("../calendar/calendar.php"); 
} else {
$CSS=1; require("calendar/calendar.php"); 
}
?>


What am I missing?

Thx…

thios works


<?php 
 if ((getcwd() == "/home/fixmy1/public_html/coronadoshores/recreation") || (getcwd() == "/home/fixmy1/public_html/coronadoshores/service")) {
require("../calendar/calendar.php"); 
} else {
require("calendar/calendar.php"); 
}
?>

This code is not very portable because you will have differnet absolute paths on different hosts. You can use basename() to overcome this problem:


$dir = basename(getcwd());
if ($dir == "recreation" || $dir == "service"  ) {
...

Ideally, in this case you’d be better off defining the absolute base path for your application somewhere in a config file - either hard-coded or better yet, derived dynamically from DIR. Then you don’t have such problems with includes and you don’t need conditional statements, you just do this:


require(BASE_ABS_DIR."calendar/calendar.php");

@lukeurtnowski;

Try this:



  $ff='calendar/calendar.php';
  if(file_exists($ff)) {require($ff);}
  if(file_exists('../'.$ff)) {require('../'.$ff);}

// or
  $ff='../calendar/calendar.php';
  if(file_exists($ff))
  {
    require($ff);
  }
  else
  {
    require( substr( $ff, 2);
  }