-1

I've a php application available in this path:

A:\Utenti\John\Programmi\Bitnami\Wampstack\apache2\htdocs\Log

I want take this full directory path, I actually tried with this:

$logPath = $_SERVER['DOCUMENT_ROOT'] . rtrim($this->_logPath, DIRECTORY_SEPARATOR);
var_dump($logPath);

but I get:

A:/Utenti/John/Programmi/Bitnami/Wampstack/apache2/htdocs/home/app_test/cfg

and should be:

A:/Utenti/John/Programmi/Bitnami/Wampstack/apache2/htdocs/Log/home/app_text/cfg

MORE DETAILS:

  1. What's $this->_logPath?

is a class variable that contains the following: home/app_text/cfg, how you can see it's join to the $_SERVER['DOCUMENT_ROOT'];

  1. Which WebServer I use?

I'm actually on Bitnami in localhost, but this system will work in any online web server.

Anyway, I almost fix the problem using this:

$logPath = __DIR__ . rtrim($this->_logPath, DIRECTORY_SEPARATOR);

that return:

A:\Utenti\John\Programmi\Bitnami\Wampstack\apache2\htdocs\Log\Log/home/app_test/cfg

how you can see the Log folder is duplicated, but I don't think that using __DIR__ should fix the problem, maybe you guys have a more elegant solution?

Dillinger
  • 1,823
  • 4
  • 33
  • 78

1 Answers1

2

I think you just need to add a / :

$logPath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . rtrim($this->_logPath, DIRECTORY_SEPARATOR);

or you can get rid of the duplicate Log directory by using dirname:

$logPath = dirname(__DIR__) . DIRECTORY_SEPARATOR . rtrim($this->_logPath, DIRECTORY_SEPARATOR); 
Gavriel
  • 18,880
  • 12
  • 68
  • 105