Validate if an input file is empty or not with PHP


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">

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

$desprendible = $_FILES["desprendible"];


echo "No hay datos";


echo "Hay datos prro";


Please can you help me.

Thanks in advance.

asked by Andres Rodriguez 03.10.2018 в 00:45

1 answer


Cordia Greeting.

I managed to solve the problem.

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


$desprendible = $_FILES["desprendible"];

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