Mkdir creates directories without permission

Asked

Viewed 93 times

1

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

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

For example: It creates the directory archives/2018.

The problem is that even if the system directory has 777 permission ( I’m using it locally ), the upload directory is created, but without permission:

inserir a descrição da imagem aqui

I’ve tried to reinforce with the command below:

chmod($diretorio, 0777);

but it did not help and this is not done the upload.

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

How can I solve this problem?

1 answer

2


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

Since the creation of files and directories is affected by the configuration of the umask, you can create files with permissions as you want if you manipulate it as follows:

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

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

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

  • Very good. I didn’t know the umask(). It worked for me. Thank you very much vnbrs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.