richardalberto
richardalberto

Reputation: 525

PHP mkdir issue!

I trying to create some dirs like this:

@mkdir("photos/$cat/$sku", 0777, true)

it creates the first directory with 0777 permissions, but when it creates the second is uses 000 as it's perms, so it fails to create the third.

A workaround this please?

Thanks, Richard.

Upvotes: 3

Views: 4506

Answers (4)

Lenny Bruyninckx
Lenny Bruyninckx

Reputation: 95

I did this and it works perfect:

    if (!is_dir($path)) {
        $dirs = explode('/', $path);
        $i = 0;
        $subdir = '';
        foreach ($dirs as $dir) {
            if($i > 0){$dir = '/' . $dir;}
            $subdir .= $dir;
            if(!is_dir(DIR_CACHE . $subdir)){@mkdir(DIR_CACHE . $subdir);@chmod(DIR_CACHE . $subdir, 0777);}

            $i++;
        }
    }

So all you have to do is define your path ( $path = photos/$cat/$sku )

Upvotes: 1

richardalberto
richardalberto

Reputation: 525

This solved the issue:

$a = @mkdir("photos/$cat/", 0777);
    @chmod("photos/$cat/", 0777);
    $b = @mkdir("photos/$cat/$sku/", 0777);
    @chmod("photos/$cat/$sku/", 0777);

but why can't use recursive on mkdir?

Upvotes: 1

Arda Xi
Arda Xi

Reputation: 2666

Have you tried chmoding the directories?

mkdir("photos/$cat", 0777, true);
chmod("photos", 0777);
chmod("photos/$cat", 0777);
mkdir("photos/$cat/$sku", 0777);
chmod("photos/$cat/$sku", 0777);

Upvotes: 0

Chirag
Chirag

Reputation: 900

dear it is due to user rights, please check the user when you are creating the any dir using mkdir function,

Upvotes: 0

Related Questions