Form clogged by enctype="multipart / form-data"

0

You see, I have the following form, which will receive a PDF and an email.

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header"><h5>Selecciona un archivo PDF para enviarselo al correo de una empresa</h5><h6>El PDF deberia estar en <b>C:/Users/pcx/Downloads</b></h6></div>

                <div class="card-body">
                    <form method="POST" action="pdf_empresa" novalidate enctype="multipart/form-data">
                        @csrf

                        <div class="form-group row">
                            <label for="email" class="col-md-4 col-form-label text-md-right">Correo Electronico de la empresa</label>

                            <div class="col-md-8">
                                <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required>

                                @if ($errors->has('email'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="archivo" class="col-md-4 col-form-label text-md-right">Archivo</label>

                            <div class="col-md-8">
                                <input id="archivo" type="file" class="form-control{{ $errors->has('archivo') ? ' is-invalid' : '' }}" name="archivo" value="{{ old('archivo') }}" required autofocus>

                                @if ($errors->has('archivo'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('archivo') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row mb-0">
                            <div class="col-md-6 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    Enviar Curriculo
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

An Email must be sent attaching the PDF:

public function envio(EnvioRequest $request){
    Mail::to($request->email)->send(new Adjuntar($request->archivo));
    return back()->with('message',['success','Se ha enviado a la empresa un email con el PDF adjunto.']);
}

And previously the form is reviewed in this request:

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class EnvioRequest extends FormRequest{
    public function authorize(){
        return true;
    }

    public function messages(){
        return[
            'email.required'=>'El correo electronico de la empresa es obligatorio', // Recuerda que esto es un vector en el que hay que poner coma entre un elemento de la cadena y otro.
            'email.email'=>'Debe ser una dirección de correo valida',
            'archivo.required'=>'Debes indicar el archivo que adjuntaras',
            'archivo.mimes'=>'Este campo debe apuntar a un fichero PDF'
        ];
    }

    public function rules(){
        return[
            'email'=>'required|email',
            'archivo'=>'required|mimes:pdf'
        ];
    }
}

The problem is that when I run the form I find that it does not capture the PDF and it gets stuck. It seems that the problem is in enctype="multipart/form-data" , because it has been include it and start the problems, but it is necessary for mimes:pdf to work, because only PDF files are allowed to upload.

    
asked by Miguel Alparez 18.05.2018 в 11:13
source

1 answer

0

I already found a solution. It consists of the change in this line of code:

Mail::to($request->email)->send(new Adjuntar($request->archivo->getClientOriginalName()));

When passing as argument $request->archivo->getClientOriginalName() , I get it to send the real name of the file even if it has been changed by enctype="multipart/form-data" .

    
answered by 18.05.2018 в 14:57