How do I check that my file type input is empty in PHP?

Asked

Viewed 587 times

0

<form action="teste1.php" method="post" enctype="multipart/form-data">  

<input type="text" name="title">
<input type="file" name="arquivos[]" multiple>

<?php
$photo=$_FILES["arquivos"];
if(empty($_FILES["arquivos"]["name"])){
    echo "vazio";
}

?>

I tried to put the variable photo in place of files but gives the same.

  • Would not be if (empty($_FILES))?

  • not working with file type, I did with text type and it works blz if(Empty($_FILES['files']['name']){ echo "empty"; }

  • Have you tried taking out the brackets? because you are sending an array like this

2 answers

0

You can check if the size of the first entry is larger than 0, that way you’ll know if you have files to upload

if ($_FILES['arquivos']['size'][0] > 0) {
    echo 'Contém arquivos';
} else {
    echo 'Vazio';
}

-1

Try it like this:

<form action="teste1.php" method="post" enctype="multipart/form-data">  
<input type="text" name="title">
<input type="file" name="arquivos" multiple>

<?php
if(isset($_POST['arquivos']))
{
$photo=$_POST["arquivos"];
if(empty($_FILES["arquivos"]["name"])){
echo "vazio";
}
}

?>


Shouldn’t have a <input type="submit" value="Enviar"> there?

  • What is the purpose of the verification isset($_GET['arquivos'])?

  • no, still the same thing.

  • I’ve always used isset($_GET['exemplo']) to make my algorithm "run"

  • @Izaacmendes has something in the variables he created in php that is not fitting, as the name inside arquivos

  • @Izaacmendes I edited php, maybe now it works

Browser other questions tagged

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