0

我正在尝试检查路径中是否已经存在来自多个上传的文件,如果是,我想排除验证错误。它的 else if 部分不起作用。number 目录是在 ajax 控制器服务器端创建的,但我想在他们将更多同名文件上传到该目录之前进行检查。这可能吗?我在这里做错了什么?

function makeProgress(number){   
          var url = getRelativeURL("web/fileUpload");   
          var formData = new FormData();
          formData.append('number', number);
          fls = document.getElementById("attachmentFileUploadInput").files; //number of files... 
          console.log(fls);
          var location = "C:/temp/" + number + "/";
          console.log(location);
          // maximum number of files at a time is 10
          if(fls.length >= 11){
              FileUploadLengthVisible(true);
              return false;
          }
          var j;
          for(j=0;j<fls.length;j++){
              if (fls[j].size > 5000000) //5MB size per file
            {
                  FileUploadSizeVisible(true);

                  return false;
            }
              else if (location + fls[j] == true)
        {
                  alert("file exists");
                  return false;
        }
              else
                  {
              formData.append('files[]', fls[j]);  //note files[] not files
              $.ajax({
                  url : url,
                  data : formData,
                  processData : false,
                  cache: false,
                  contentType: false,
                  type : 'POST',
                  success : function(data) {
                   FileUploadVisible(true);

                   $('#attachmentModal').modal('hide')
                   $(':input','#attachmentModal').val("");
                    $("#pbarmain").hide();
                    $("#pbar").hide();
                    $("#actionPlanDiv").hide();
                    setObjectEnabled('#Upload',false);

                  },
                  error : function(err) {
                      FileUploadErrorVisible(true);

                  }

             });
              console.log('loop each file working');
          }
          }
          console.log("form data " + formData);


            }
4

0 回答 0