Codefor Codefor - 4 months ago 19
Linux Question

PHP Warning: mkdir(): Not a directory when creating directory

I'm trying to recursively create directories, but I get this PHP warning:

Code:

<?php mkdir('data/1/0', 0755, true);


Output:

PHP Warning: mkdir(): Not a directory in /home/myScript.php on line 1


This is running on Linux.

Answer

from the manual book,we can see:

bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )

http://www.php.net/manual/en/function.mkdir.php

When we try to mkdir 'data/1/0',actually we can mkdir '0' under the directory 'data/1'.But when 'data/1' happen to be a file , not directory,php will issue a warning PHP Warning: mkdir(): Not a directory

So,when you come with this warning ,you can check wether the prefix of the pathname is a file ,where a directory expected.