PHP mkdir( $recursive = true ) skips last directory

NDM picture NDM · Sep 9, 2009 · Viewed 39k times · Source

I've got the following piece of code on a PHP 5.2.4 (no safe_mode) linux server:

mkdir( $path, 0777, true );

when I enter a path like:

'/path/to/create/recur/ively/'

all directories are created except for the last one... when I add another directory like:

'/path/to/create/recur/ively/more/'

again, all paths are created except for the last one...

have tried both with and without trailing slashes

Can any1 enlighten me here please?

Answer

NDM picture NDM · Sep 23, 2009

Ok the solutions is as follows: there was no problem.

I did not test the code in isolation, but only assumed the following code was not doing anything to the directory structure...

as I found out the directory got deleted later on by the code itself.

Anyway, Lesson learned...