Check if Input :: file exists Laravel

5

I have a class created by me that uploads files. I would like to check if Input :: file ('image') exists, because if it does not exist, it does not upload the image.

Follow my code:

if(Input::has('name')){
    $file = Input::file('imagem');
    $uploadClass = new UploadFile();
    $uploadClass->setFile($file);
    $uploadClass->randomFileName();
    $uploadClass->setMaxFileSize(1048576);
    $uploadClass->setAcceptedExtensions(['jpg','jpeg','png','zip']);
    $uploadFeito = $uploadClass->uploadFile('uploads');

    if (!$uploadFeito) {
        return Redirect::back()
        ->with('alerta_erro', $uploadClass->getMessage())
        ->withInput();  
    }
}
    
asked by anonymous 13.05.2015 / 22:02

1 answer

3

I solved my problem, instead of Input::has('imagem') , use Input::hasFile('imagem') .

    
14.05.2015 / 02:33