Why chdir("..") is not working?
I want to go up two directories from the current working directory.
I use开发者_运维技巧d 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 ?
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.';
}
精彩评论