user833129
user833129

Reputation:

Why chdir("..") is not working?

I want to go up two directories from the current working directory.

I used chdir("..") two times to make the move. And after that I call mkdir("directoryname") ; but when I looked at the operating system ( Linux Ubuntu ) then the directory is not created ; even though I already set the chmod 777 to the parent directory into which I want to create the new directory. So how to mount up two directories level with PHP ?

Upvotes: 1

Views: 4120

Answers (1)

VolkerK
VolkerK

Reputation: 96159

Verify "where" your script started and where it is after the two chdir()s via

echo getcwd();

also test the return value of mkdir

if ( mkdir($path) ) {
  echo 'done'.
}
else {
  echo 'failed.';
}

or use getcwd() or _FILE_, _DIR_ (or whatever is suitable) and dirname() to create an abosulte path for mkdir()

$d = getcwd();
echo 'start: ', $d, "\n";
$d = dirname(dirname($d));
echo 'target: ', $d, "\n";

$d .= '/directoryname';
echo 'creating ', $d, "\n";
if ( mkdir($d) ) {
    echo 'done.';
}
else {
    echo 'failed.';
}

Upvotes: 2

Related Questions