Mkdir creates directories without permission

1

I have an upload system where a directory is created as follows:

$diretorio = mkdir("../../arquivos/".$anoEdicao,0777);

Eg: It creates the files / 2018 directory.

The problem is that even the system directory is allowed 777 (I'm using locally), the upload directory is created, but without permission:

Ihavetriedtoreinforcewiththecommandbelow:

chmod($diretorio,0777);

Butitdidnotworkanditisnotuploaded.

if(move_uploaded_file($temp,$diretorio."/".$codArquivo)){
....
}

How can I resolve this problem?

    
asked by anonymous 14.02.2018 / 12:43

1 answer

2

umask is the command that determines the settings of a mask that controls what file permission will be given to new files created on the system. Each process in the operating system has its own mask.

Since file and directory creation is affected by the setting of umask , you can create files with permissions as you want by manipulating it as follows:

$antigo = umask(0);
$diretorio = mkdir("../../arquivos/".$anoEdicao,0777);
umask($antigo);

See that I change the umask to 0 and then return to its old value, to avoid any future problems.

If you want to know more about umask , see here. And PHP documentation about it.

    
14.02.2018 / 12:57