Check if Input::file exists Laravel

Asked

Viewed 764 times

5

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

Just 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();  
    }
}
  • you tried to do that way ?

  • I tried using Input::has('image') but n worked.

1 answer

3


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

Browser other questions tagged

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