phpchdir

PHP Using variables inside chdir()?


Using PHP,

chdir('../) works completely fine. However, when going the same path just having a declared variable instead, it prompts an error saying:

Warning: chdir(): No such file or directory (errno 2)

$var = "../";
chdir($var)

I have tried declaring $var with 's instead, and also tried to use " inside chdir but both cases gives same error.

why is this?


Solution

  • Late update, but the solution was to trim the variable in advance.

    $query = '../';
    chdir(trim($query));
    

    When I posted this issue, I was not familiar with how to oppose the issue in a matter of clarity, but I still should've included that the variable input actually was originating from a textfield.

    Thanks for all the support, however!