PHP测试表单是否上传了文件
我该怎么做?这些不起作用:PHP测试表单是否上传了文件,php,forms,Php,Forms,我该怎么做?这些不起作用: if(empty($_FILES)){ echo "there is no file uploaded"; exit; } else { echo "there is file"; } if(sizeof($_FILES)!=0){ echo "there is file"; } else { echo "there is no file"; } 发件人: “如果$\u文件为空…请尝试将enctype=“multipart/form data”
if(empty($_FILES)){
echo "there is no file uploaded";
exit;
} else {
echo "there is file";
}
if(sizeof($_FILES)!=0){
echo "there is file";
} else {
echo "there is no file";
}
发件人:
“如果$\u文件为空…请尝试将enctype=“multipart/form data”
添加到表单标记,并确保已打开文件上载。”您可以使用is\u数组($\u文件)检查它是否包含数组格式的文件信息
样本:
<?php
if (isset ( $_FILES ['image'] )) {
if ($_FILES ["image"] ["error"] == UPLOAD_ERR_OK) {
echo "File Was Uploaded AND OK";
} else {
echo "File Was Uploaded but BAD";
}
} else {
echo "No File Uploaded";
}
?>
<form method="post" enctype="multipart/form-data">
<label for="file">Filename 1:</label> <input type="file" name="image"
id="file" /> <br /> <input type="submit" name="submit" value="Submit" />
</form>
文件名1:
你可以在这里看到更多的例子。不工作。谢谢
if(count($\u FILES)>0){}
您检查了吗?另外,请确保您的表单设置为POST而不是GET。@Dale,不知何故,这将始终返回false。如果您设法上传文件,则不会:-)您没有使用method=“GET”是吗?;-)谢谢这就是我需要的。我想测试用户是否在有文件输入的情况下也没有提交文件。