How do I check if a $ _FILE has been set?

1

All right?

I'm trying to run this code:

if(empty($_FILES['imagem']['name'])){
    $upload = new Upload();
    $novoNome = $upload->efetuarUpload($_FILES["imagem"]);
    $pontoTrocaAlterado->setImagem($novoNome);
}

I need only when the user uploads the file, it performs the Upload function and sets the new image name. However doing the tests, even when the user does not upload the file, the name is changed.

I've used several functions like:

in_array array_key_exists

But I did not succeed, could anyone help me?

    
asked by anonymous 28.06.2017 / 21:22

1 answer

2

I was able to resolve, as it was a case of file change, I did the following:

    if(!empty($_FILES['imagem']['name'])){
    $upload = new Upload();
    $novoNome = $upload->efetuarUpload($_FILES["imagem"]);
    $bannerAlterado->setImagem($novoNome);
}else{
    $bannerAlterado->setImagem($imagem);
}   

I followed the suggestion of @AndersonCarlosWoss to add ! , but I noticed that even though I did not define the name it did not write to the bank, because the bank does not accept null, so I recorded the old file name .

    
28.06.2017 / 21:42