LBO's avatar
Level 1

UPLOAD OF ARCHIVES | LARAVEL 5.4

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

upload.blade
<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)
        {

            // Retrieve the original file name
            $ Filename = $ files-> getClientOriginalName ();

            // Retrieve the file extension
            $ Extension = $ files-> getClientOriginalExtension ();

            // Defining a unique name for the file
            $ Name = $ filename. '.' . $ Extension;

            // Directory where the files will be saved
            $ DestinationPath = storage_path ('documents');

            // Move the file to the specified folder
            $ Files-> move ($ destinationPath, $ name);
        }


        Session :: flash ('flash_message_success', 'Document loaded successfully!');
        Return redirect () -> action ('DocumentsController @ upload');
    }
    Else
    {
        Session :: flash ('flash_message_error', 'File not loaded, please try again!');
        Return redirect () -> action ('DocumentsController @ upload');
    }

So far so good, the files are loaded into the destination folder, but you can not open them. Looks are corrupted.

Any idea what that might be?

0 likes
0 replies

Please or to participate in this conversation.