RealPath () function does not accept variable

1

Well, when I put this in:

$rootPath = realpath("/home/687_332_0/332");
echo $rootPath;

The above example will print: 687_332_0 / 332 ( RUN! )

However, when I put what is below, echo does not work :

$rootPath = realpath("/home/".$folder1."/".$folder2);
ou $rootPath = realpath('/home/'.$folder1.'/'.$folder2);
ou $rootPath = realpath("/home/$folder1/$folder2");

ou o mesmo processo com essas variáveis convertidas com strval() ou (string)
$caminho1 = strval($folder1);
$caminho2 = (string)$folder2;

echo $rootPath;

The above example will print: NOTHING!

Why does this happen and how do I resolve it?

    
asked by anonymous 09.06.2015 / 23:39

1 answer

1

A little clarification about the realpath function: It will return FALSE if the path of pasta or arquivo does not exist.

Example:

var_dump(realpath('nao_existe/essa_pasta')); // bool(false)

I think the most appropriate way to mount the path path would be:

$rootPath = "/home/".$folder1."/".$folder2;

if (! is_dir($rootPath)) {
  // Faça alguma coisa se essa parta não existir
}

// ... Continua o código
    
18.08.2015 / 19:20