Donny
Donny

Reputation: 47

PHP:mkdir() can't create folder

I know there are similar topics,but when I tried using them, I still got the same error. The problem is this:

Warning: mkdir() [function.mkdir]: No such file or directory in /home/... on line 30

I got this code:

$id = mysql_insert_id();
mkdir("memberFiles/$id", 0755);

What's the problem?I already have memberFiles folder.

Upvotes: 0

Views: 1684

Answers (1)

René Höhle
René Höhle

Reputation: 27285

Use the complete path to your file. You can use it with __DIR__ then you have the actual directory form your file.

mkdir(__DIR__."/memberFiles/$id", 0755);

for example. And you should check if the directory is available before you try create it.

if(!is_dir(__DIR__."/memberFiles/$id")) {
    mkdir(__DIR__."/memberFiles/$id", 0755);
}

If you have PHP < 5.3 then its dirname(__FILE__) instead of __DIR__.

Upvotes: 1

Related Questions