检查特定的输入文件是否为空 [英] Check if specific input file is empty
本文介绍了检查特定的输入文件是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的表单中,我有3个用于文件上传的输入字段:
In my form I have 3 input fields for file upload:
<input type=file name="cover_image">
<input type=file name="image1">
<input type=file name="image2">
如何检查cover_image
是否为空-没有文件可上传?
How can I check if cover_image
is empty - no file is put for upload?
推荐答案
您可以使用$_FILES
数组上的size
字段进行检查,如下所示:
You can check by using the size
field on the $_FILES
array like so:
if ($_FILES['cover_image']['size'] == 0 && $_FILES['cover_image']['error'] == 0)
{
// cover_image is empty (and not an error)
}
(我也在这里检查error
,因为如果出现问题可能是0
.我不会使用name
进行此检查,因为这可以被覆盖)
(I also check error
here because it may be 0
if something went wrong. I wouldn't use name
for this check since that can be overridden)
这篇关于检查特定的输入文件是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文