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

0

Hello, I'm having trouble writing to a directory in laravel 5.6, I created the directory on the server and when I upload it it gives this error:

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

curious that I have another directory "avatar" and use the same way to save images in the two. I can save on the internal server, but when I upload I can not, it follows the codes:

Code that saves in "signature" that says I am not allowed:

        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 without errors:

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{
                    ...
    
asked by anonymous 18.10.2018 / 15:10

1 answer

1

Permission error:

If you are on Linux

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

Uploads are usually made to folders:

- storage/app
- public/

The $(whoami) function returns the name of your user. If you happen to be another user as www-data , just change the above command.

If you are in Windows

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

You can also go to the Security tab and try to apply permissions to all users of Reading and Writing, etc.

    
18.10.2018 / 15:27