Problems with permissions when creating folders on Linux server using mkdir

3

I have a PHP system using Laravel 4.2 where I use the mkdir command to create a folder in the storage / pdf directory, the command works in the Windows Dev environment, but when uploading to the UOL server the folders are not created properly, I'm using the following code snippet:

$diretorio = storage_path() . "/pdf/" . \Auth::user()->ID;
$this->verificarEDeletarDiretorioExistente($diretorio);
mkdir($diretorio, 0777);

// Lógica para criar arquivo na pasta e enviar

$this->verificarEDeletarDiretorioExistente($diretorio);

I searched the internet but found nothing that referred to this problem. The UOL server is a Red Hat Enterprise Linux Server release 6.5 (Santiago).

For better analysis, follow the checkboxDeleteDirectoryExist method ($ directory):

private function verificarEDeletarDiretorioExistente($diretorio)
{
    if (is_dir($diretorio)) {
        $diretorioScan = array_diff(scandir($diretorio), array('.', '..'));

        foreach ($diretorioScan as $content) {
            unlink($diretorio . "/" . $content);
        }

        rmdir($diretorio);
    }
}
    
asked by anonymous 11.07.2017 / 16:35

2 answers

0

If the full path of storage_path() does not exist on the server, you must set the recursion parameter to TRUE , so that the full path is created recursively, see function documentation .

If the path already exists and you just want to create the pdf directory and you are having problems with the usage mode, the subdomain may have to use chmod and set the permissions of the subdomains individually as there is no recursion in this command.

    
12.07.2017 / 03:27
0

Today I had the same problem. In localhost the method created the directory and performed the function without problems, but in the client it did not work, giving a path error.

I solved the method by setting the recursive parameter to true. For your problem: Try

mkdir($diretorio, 0777, true);
    
07.10.2017 / 06:21