File problem after upload, in Laravel 5.4

Asked

Viewed 630 times

0

I have the following code to upload files to my Laravel application.

upload.

<div class="form-group">
 <label for="name" class="col-sm-3 control-label">Documento *:</label>
    <div class="col-sm-6">
        <input  type="file" multiplename="docs[]"/>
    </div>
</div>

Documentscontroller

public function move(Request $request)
{

    if ($request->hasFile('docs')) {

        $doc = $request->file('docs');


        foreach($doc as $files)
        {

            //Recupera o nome original do arquivo
            $filename  = $files->getClientOriginalName();

            //Recupera a extensão do arquivo
            $extension = $files->getClientOriginalExtension();

            //Definindo um nome unico para o arquivo
            $name  = $filename . '.' . $extension;

            //Diretório onde será salvo os arquivos
            $destinationPath = storage_path('documents');

            //Move o arquivo para a pasta indicada
            $files->move($destinationPath, $name);
        }


        Session::flash('flash_message_success', 'Documento carregado com sucesso!');
        return redirect()->action('DocumentsController@upload');
    }
    else
    {
        Session::flash('flash_message_error', 'Arquivo não carregado. Tente novamente!');
        return redirect()->action('DocumentsController@upload');
    }

}

So far so good, the files are loaded into the destination folder, but it is not possible to open them. Below jpeg files error and also get PDF error.

inserir a descrição da imagem aqui

Any suggestions?

  • You can open . jpeg on the Notepad?

  • Thanks for the return William. I am at work, as soon as I get home I will try your tip. Imagine what it might be? Ah, I’m running the application on Localhost, believe me I may have something to do?

  • @L.B.The temporary folder lacks permission depending on your PHP configuration, but usually in the folder c:\Windows\Temp for Windows missing write permission, have to see the server user you are using.

  • 1

    @Virgilio probably when uploading the files to the hosting and giving read and write permission in the folder should work. I will test and give you a feedback. Thank you for your attention.

  • So yesterday I had a problem like Wampserver. It stopped working and I had to reinstall it. While setting up my application again I performed the file upload test, funny that the error that was occurring stopped and the above code is working normally.

No answers

Browser other questions tagged

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