Permissive issues when creating Linux server folders using mkdir

Asked

Viewed 451 times

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 climbing to the UOL server the folders are not created properly, I am 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 I couldn’t find anything that referenced this problem. The UOL server is a Red Hat Enterprise Linux Server release 6.5 (Santiago).

For best analysis follow the method checkEDeletarDirectoryExistent($directory):

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

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

        rmdir($diretorio);
    }
}
  • The first thing to do is check the error logs.

3 answers

1


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

I decided to set the method to true the recursive parameter. To deal with your problem: Try

mkdir($diretorio, 0777, true);

0

The best check is to enter the server and create a simple php script to test the creation through the mkdir function...

<?php
mkdir('/storage/pdf/content', 0700, true);
chmod('/storage/pdf/content', 0777);
?> 

If at the end the folder is not allowed 777 then it may be something related to Selinux (if enabled), then you will need to take a look at the semanage in RHEL 6.

0

If the complete path of storage_path() does not exist on the server, you must set the recursion parameter as TRUE, to create the full path recursively, see job documentation.

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

Browser other questions tagged

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