我试图在表单发布时添加if else语句,而不是用户是否包含文件?

Kee*_*ezy 1 html php if-statement isset

我怎么做这样的if/else语句?用户可以选择是否添加图像.如果添加图像,我想要运行if,如果他们不希望别人运行,因为根据是否添加图像,他们将有两个不同的结束.

if (isset($_POST['formsubmitted'])) { 

if (isset($_POST['name'])){  }else{  }

if (isset($_POST['state'])){  }else{  }

if (isset($_FILES['images']['name'])) { echo 'images'; exit;} else {echo 'no images'; exit;}


} #end main form submitted
Run Code Online (Sandbox Code Playgroud)

if(isset($ _ FILES ['images'] ['name']))dosnt工作,因为截至目前,即使没有提交图像,它仍然会提交图像.

html文件字段是:

<form>
<input type='file' name='images[]' id=''>
<input type='file' name='images[]' id=''>
<input type='file' name='images[]' id=''>
<input type = "submit">    
</form>
Run Code Online (Sandbox Code Playgroud)

Que*_*ter 5

你应该试试这个

Submit.php

<pre>
<?php 
// those index are empty the array filter remove this 

echo "without filter"."<br>";
print_r($_FILES['images']['name']);

echo "filter"."<br>";
$usersFileUpload = array_filter($_FILES['images']['name']);
print_r($usersFileUpload);

$usersFileUploadCount = count($usersFileUpload);

for($i=0;$i<=$usersFileUploadCount;$i++){
    echo $usersFileUpload[$i]."<br>";

    // insert Table     
}
?>
Run Code Online (Sandbox Code Playgroud)

HtmlForm.php

<form action="submit.php" method="post" enctype="multipart/form-data" name="images">
<input type='file' name='images[]' id=''><br />
<input type='file' name='images[]' id=''><br />
<input type='file' name='images[]' id=''>
<input name="" type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)

查看图片以进行验证1

在此输入图像描述

查看图片以进行验证2

在此输入图像描述