I am not allowed to write in a directory in Laravel 5.6

Asked

Viewed 571 times

0

Hello, I’m having trouble writing in a directory in Laravel 5.6, I created the directory on the server and when I will upload it gives this error:

unable to write in the "uploads/imagens/assinatura" directory

curious that I have another "avatar" directory and use the same way to save images in both. I can save on the internal server, but when I go up I can’t, follow the code:

Code saved in "signature" that says I don’t have permission:

        if($request->hasFile('ds_ass')){
            $destino = 'uploads/imagens/assinatura';
            $arquivo = $request->ds_ass;
            $nmArquivo = $id.'-'.date('d').'-'.date('m').'-'.date('Y').'-'.date('i').'-'.date('s');
            $extensao = $arquivo->getClientOriginalExtension();
            $nomeArquivo = $nmArquivo.'.'.$extensao;
            $arquivo->move($destino,$nomeArquivo);
            $foto = $arquivo;
            $salvaFoto = new \App\Anexos;
            $salvaFoto->ID_CD_PESSOA = $id;
            $salvaFoto->DS_ARQUIVO = $nmArquivo;
            $salvaFoto->DS_EXTENSAO = $extensao;
            $salvaFoto->save();

            $fotoprof = $prof::find($idProf);
            $fotoprof->DS_ASSINATURA = $nomeArquivo;
            $fotoprof->save();
        }else{
              ...

Code that runs error-free:

if($request->hasFile('ds_arquivo')){
                    $destino = 'uploads/imagens/avatar';
                    $arquivo = $request->ds_arquivo;
                    $nmArquivo = $id.'-'.date('d').'-'.date('m').'-'.date('Y').'-'.date('i').'-'.date('s') ;
                    $extensao = $arquivo->getClientOriginalExtension();
                    $nomeArquivo = $nmArquivo.'.'.$extensao;
                    $arquivo->move($destino,$nomeArquivo);
                    $foto = $arquivo;
                    $salvaFoto = new \App\Anexos;
                    $salvaFoto->ID_CD_PESSOA = $id;
                    $salvaFoto->DS_ARQUIVO = $nmArquivo;
                    $salvaFoto->DS_EXTENSAO = $extensao;
                    $salvaFoto->save();

                    $fotoPessoa = \App\Pessoas::find($id);
                    $fotoPessoa->DS_FOTO = $nomeArquivo;
                    $fotoPessoa->save();
                }else{
                    ...

1 answer

1


Error of permission:

If you are on Linux

chmod -R 755 /diretorio/do/seu/projeto
chown -R $(whoami):$(whoami) /diretorio/do/seu/projeto

Usually uploads are done in folders:

- storage/app
- public/

The function $(whoami) returns your user name. If by chance it is another user as www-data, just change in the above command.

If you are on Windows

Go to folder, right click, properties, deselect read-only and try again.

You can also go in the tab Security and try to apply permissions to all Read and Write users, etc.

Browser other questions tagged

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