如何在将数据上传到数据库之前检查数组输入类型文件为空。如果有一个空,则显示用户所理解的任何内容,且不更新数据。
这是示例代码html
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="Upload">Upload</label></th>
<td>
<form action="" method="post">
<input name="profile_photo[]" type="file" value="" />
<input name="profile_photo[]" type="file" value="" />
<input name="profile_photo[]" type="file" value="" />
<br/>
</form>
</td>
</table>在上传到数据库之前,我经常使用$x=$_GET‘’profile_photo‘;和回显$x;,它返回空或null。
发布于 2013-05-08 17:05:40
$x=$_FILES['profile_photo']['name']; 使用此代码
发布于 2013-05-08 17:04:49
if (!empty($_FILES) && is_array($_FILES)) {
// you have files
}发布于 2013-05-08 17:05:48
只需在post数据上运行for循环并验证
$error = "";
$emptyFiles="";
$i=0;
foreach ($_FILES['profile_photo'] as $name) {
if (isset($name['name']) && $name['name']!="") {
$error.="";
} else {
$error.= "yes";
$emptyFiles.=$_FILES['profile_photo'][$i];
}
$i++;
}然后使用
要获取的$error和$emptyFiles字符串,哪些是空字段,哪些不是。
https://stackoverflow.com/questions/16436545
复制相似问题