如何删除"input type = file"的具体值

Div*_*iya 8 html javascript php jquery

我使用输入类型='文件'与多个文件和一个单个文件.喜欢,

//single image
//IMAGE_TYPES is constant and defined with:define('IMAGE_TYPES',array('main','floor','bedroom1','bedroom2','bedroom3','kitchen','reception','garages','epc','other'));
@foreach(IMAGE_TYPES as $images)
    @if($images!='other')
    <div class="col-sm-10">
        <input type="file" class="form-control" id="{{$images}}_image" name="{{$images}}_image" accept="image/*" placeholder="<span> <i class='fa fa-plus-circle'></i>Click here or drop files to upload</span>"/>
    </div>
    @else
    //multiple
    <div class="col-sm-10">
        <input type="file" class="form-control" id="other_images" name="other_images[]" accept="image/*" placeholder="<span> <i class='fa fa-plus-circle'></i>Click here or drop files to upload</span>" multiple />
    </div>
    @endif
@endforeach
Run Code Online (Sandbox Code Playgroud)

现在,我用jquery验证它,

var image_type ='<?=json_encode(IMAGE_TYPES);?>';
image_type = JSON.parse(image_type);
var max_image_size = 2;
$.each(image_type, function( index, value ) {
  if (value!='other') {
    $('#'+value+'_image').bind('change', function() {
      var a=(this.files[0].size);
      var ValidImageTypes = ["image/jpeg", "image/png"];
      if ($.inArray(this.files[0].type, ValidImageTypes) < 0) {
        show_notification('error','Only .jpg/.jpeg and .png file allowed. Please select other image.');
        var file = document.getElementById(value+'_image');
        file.value = file.defaultValue;
        return false;
      }
      else{
        if (Math.round(a / (1024 * 1024)) > max_image_size) {
          show_notification('error','Image is Greater than '+max_image_size+'MB. Please select smaller image.');
          var file = document.getElementById(value+'_image');
          file.value = file.defaultValue;
          return false;
        }
        else
        {
          preview_main_image(value);//won't matter
        }
     }
    });
  }
  else{
    $('#other_images').bind('change', function() {
      $('div.add_preview').remove();//won't matter
      for (var i = 0; i < $("#other_images").get(0).files.length; i++) { 
        var a=(this.files[i].size);
        var name = this.files[i].name;
        var ValidImageTypes = ["image/jpeg", "image/png"];
        if ($.inArray(this.files[i].type, ValidImageTypes) < 0) {
          show_notification('error','Image '+name+' is Not allowed. Only .jpg/.jpeg and .png file allowed. Please select other image.');
        }
        else{
          if (Math.round(a / (1024 * 1024)) > max_image_size) {
            show_notification('error','Image '+name+' is Greater than '+max_image_size+'MB. Please select smaller image.');
          }
          else
          {
            $('#other_image_preview').append("<div class='col-md-2 p_3 add_preview'><img class='img-responsive' src='"+URL.createObjectURL(event.target.files[i])+"'></div>");//won't matter
            //preview_detail_images(value);
          }
        }
      }
    });
  }
});
Run Code Online (Sandbox Code Playgroud)

现在,我的问题是当我使用单个图像时如果图像不适合验证然后我从输入类型='文件'使用,删除它的值,此代码

var file = document.getElementById(value+'_image');
file.value = file.defaultValue;
return false;
Run Code Online (Sandbox Code Playgroud)

但是当我选择多个图像并且如果任何图像不适合验证时,我如何从输入类型='文件'中删除该特定图像.

请帮我

mix*_*ble 0

您可以在处理上传的文件时忽略服务器上的此文件类型。这是更好的解决方案,因为它更安全。当您依赖 JavaScript 时,可以很容易地将受操纵的数据发送到您的服务器并上传其他图像的文件类型(甚至是诸如jsphp、 ... 之类的脚本)。