views:

1346

answers:

4

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 axcept 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?

+1  A: 

Try to remove the trailing slash from your path.

At least that's how it's being used in the examples of the mkdir documentation.

Personally I can't remember having problems, but I usally don't append trailing slashes, so go and try that.

UPDATE:

I just tried your code and it created every directory including the last one. I'm running Mac OS X 10.5. No idea why it's not working for you :-(

That's the code I used:

<?php
$path = '/Users/andre/test/bla/foo';
mkdir( $path, 0777, true );

Sorry, seems like I'm of no help here.

André Hoffmann
That was about the first thing I did, but it still yields the same results...
Nicky De Maeyer
A: 

If you tried everything and it keeps not working, then add some text in the end of the path like:

$path = '/path/to/create/recur/ively/more/this_wont_be_created_anyway';
w35l3y
That's how I 'solved' it in the current code...But it doesn't really make any sense...
Nicky De Maeyer
thats a dirty work-around and does not help the question asked...> Can any1 enlighten me here please?
Gnark
You should never use code that you don't understand.
André Hoffmann
@Sophomore - enlighten you with what?
thephpdeveloper
@Andre - agree totally. else side effects might just trigger.
thephpdeveloper
I agree this is a work-around but hey, he said he tested the solutions that people had posted already
w35l3y
+1  A: 

What is your PHP version? Is safe_mode turned on?

If so, then it could be that you are experiencing http://bugs.php.net/bug.php?id=43276

Anti Veeranna
5.2.4 without safe_mode, so it's not applicable, I've also tried with and without trailing slashes so....
Nicky De Maeyer
+1  A: 

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...

Nicky De Maeyer