I been trying for hours to get the name of the public folder on a remote server using an ssh2 connection.
On some servers the public directory is "public_html" but others may be "htdocs". I don't want to hard code the name in my code, much better to get the correct name from the server. I can't figure out why "pwd" works but $_SERVER array and dirname do not.
I read the documentation at: https://www.php.net/manual/en/function.ssh2-exec.php There is no place that they describe which PHP commands are supported and which are not supported.
Can someone please explain what I might be doing wrong or what I am missing?
//$stream = ssh2_exec($connection, "pwd;"); // This command works returns /home/username
//$stream = ssh2_exec($connection, "dirname(__DIR__);"); // returns null
$stream = ssh2_exec($connection, "$_SERVER['DOCUMENT_ROOT'];"); // Returns error "Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING)..."
stream_set_blocking( $stream, true );
$remotePublicDirectory = "";
while( $buffer = fread($stream,4096) ){
$remotePublicDirectory .= $buffer;
}
fclose($stream);
$remotePublicDirectory = trim($remotePublicDirectory);
echo '$remotePublicDirectory = ' . $remotePublicDirectory . '<br/>';