php – Permissions issues when creating folders on Linux server using mkdir


I have a system in PHP 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 UOL's server the folders are not created properly, I'm using following code snippet:

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

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


I searched the internet but I didn't find anything that makes reference to this problem. UOL's server is a Red Hat Enterprise Linux Server release 6.5 (Santiago).

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

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

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



Today I went through the same problem. In localhost, the method created the directory and performed the function without problems, but on the client it didn't work, giving a path error.

I decided by setting the method with true the recursive parameter. For your problem: Try

mkdir($diretorio, 0777, true);
Scroll to Top