Validate if an input file is empty or not with PHP

1

Cordial Greeting.

I hope you are well, and you can help me.

What I do is, I have an HTML form, which sends data by POST, to PHP, a field is an input of type file (input="file" >), and I receive it in PHP, what I want to validate is whether the varible comes with a file or not.

<form method="POST" action="php/archivo.php" id="frm_contact" name="frm_contact" enctype="multipart/form-data">

 <input type="file" class="aweform" name="desprendible">
<input type="submit"  class="myButton" id="btn-enviar" Value="Enviar">
</form>

/// --------------------- PHP File ----------------- //

$desprendible = $_FILES["desprendible"];

if(empty($desprendible)){

echo "No hay datos";

}else{

echo "Hay datos prro";

}

Please can you help me.

Thanks in advance.

    
asked by Andres Rodriguez 03.10.2018 в 00:45
source

1 answer

2

Cordia Greeting.

I managed to solve the problem.

If someone presents the same inconvenience, I leave the solution.

Archivo.php

$desprendible = $_FILES["desprendible"];

if ($_FILES['desprendible']['name'] != null) {
echo "Tiene datos La variable";
}else{
echo "No hay datos";
}
    
answered by 03.10.2018 / 15:42
source