Php 为什么在jqueryvalidate返回错误后,upload字段不能选择新文件?

Php 为什么在jqueryvalidate返回错误后,upload字段不能选择新文件?,php,validation,file,upload,jquery-validate,Php,Validation,File,Upload,Jquery Validate,我正在使用PHP和jQuery编写表单。我有一个文件上载字段,应用了以下jQuery验证规则: image: { accept: "jpeg|jpg|png|gif", required: "#edit_ID:blank" } 文件上载字段只能接受jpeg/jpg、png或gif图像。仅当ID为edit_ID的字段留空时,才需要该字段 这是我的文件上载字段: <input type="file" id="image" name="image" class="input1" />

我正在使用PHP和jQuery编写表单。我有一个文件上载字段,应用了以下jQuery验证规则:

image: {
 accept: "jpeg|jpg|png|gif",
 required: "#edit_ID:blank"
}
文件上载字段只能接受jpeg/jpg、png或gif图像。仅当ID为edit_ID的字段留空时,才需要该字段

这是我的文件上载字段:

<input type="file" id="image" name="image" class="input1" />
文件上载字段选择没有任何问题的文件,但是当jQuery由于违反规则而返回错误时,即使我从计算机中选择了一个新文件,在错误出现之前选择的文件仍保留在那里。这就好像在jQueryValidate给出错误后,它被禁用了一样

我尝试删除此字段的规则集,并对其进行了测试,没有遇到任何问题

有人知道是什么导致了这个问题吗

谢谢


注:我在Firefox v.3.6.9和IE v.8中遇到了这个问题,但在Google Chrome v.5中没有遇到。

从技术上讲,这不会回答您最初的问题

但是,信任客户端编程来进行图像验证不是一个好主意;你的程序可能会被愚弄。既然您使用的是PHP,为什么不使用PHP进行一些服务器端验证呢

上载的所有文件都存储在$\u文件数组中。您可以这样检查文件类型:

<?php
    foreach($_FILES as $file)
    {
        if(!empty($file['type'])) //only check if there's a valid file type
        {
            if($file['type'] != 'image/jpeg' && $file['type'] != 'image/png' && $file['type'] != 'image/gif')
            {
                //this file is not any one of the accepted formats, so long!
            }
            else{//do your processing}
        }
        else{//error invalid file}
    }
?>

如果您想要即时验证,您仍然可以使用AJAX,而不是仅仅依靠客户端来进行验证。

我更喜欢使用客户端验证,这样在显示错误之前用户就不会进入其他页面。如果我不知道如何解决jQuery问题,那么也许我会使用PHP。