似乎有很多人问这个问题并没有得到答案。检查表单的文件上传部分是否已填写是否存在问题?这是因为它是一个全局变量并且总是设置的吗?
我遇到的问题是检查文件输入 ytpe 是否已填写。
下面的代码显示了检查文件字段是否由用户填写的各种示例。
当它被填写时,他们都没有发现:
<?php
if (isset($_POST['add']))
{
//if (!isset($_POST['pic'])) { echo"pic not filled in";}else{echo"pic filled in";}
if (!isset($_POST['pic'])) { echo"pic not filled in";}
if (isset($_POST['pic'])) { echo"pic filled in";}//end of check to see if picture has been filled in
//if (!isset($_POST['userfile[]'])) { echo"pic not filled in";}
//if (isset($_POST['userfile[]'])) { echo"pic filled in";}//end of check to see if picture has been filled in
//$pictureName = $_REQUEST['pic'];
//if ($pictureName == ''){echo"pic is blank";}
//else{echo"pic is NOT blank";}
//if ($_POST['pic'] == ""){echo"pic is blank";}
//else {echo"pic is NOT blank";}
}
else
{
/////////render form
?>
<form enctype="multipart/form-data" action="" method="post" id="save"><fieldset>
<input type="text" name="fileName" id="fileName" value=""/>
<input type="file" name="userfile[]" id="pic" />
<input name="add" id="save_button" type="submit" value="Update"/>
</fieldset></form>
<?php
}
?>