为了账号安全,请及时绑定邮箱和手机立即绑定

现在的情况是alert已经出来了,可是文件还是上传上去了?

现在的情况是alert已经出来了,可是文件还是上传上去了?

开心每一天1111 2022-10-19 15:15:47
功能是要上传一个文件,判断这个文件名称是否已存在,存在的话提示用户修改文件名称。Java代码  'onSelect': function(e, queueId, fileObj) {  if(checkFileNames(fileObj.name)){  alert("已存在名为:" + fileObj.name + "的文件,请修改文件名称!");  return false;  }  },  onSelect方法如上面所示,checkFileNames用于判断文件名是否已存在,存在返回true,不存在返回false。现在的情况是alert已经出来了,可是文件还是上传上去了。怎么破?求大神~!~
查看完整描述

2 回答

?
胡说叔叔

TA贡献1804条经验 获得超8个赞

做过类似的东西,是在onUploadStart中判断的,弄了好久才搞定
'onUploadStart': function (file) {

    var myself = this;
    if(已存在){
      myself.cancelUpload(file.id);
      $('#' + file.id).remove();
    }
}


是根据uploadify源码中改的

// Triggered right before a file is uploaded
        onUploadStart: function (file) {
            // Load the swfupload settings
            var settings = this.settings;

            var timer = new Date();
            this.timer = timer.getTime();
            this.bytesLoaded = 0;
            if (this.queueData.uploadQueue.length == 0) {
                this.queueData.uploadSize = file.size;
            }
            if (settings.checkExisting) {
                $.ajax({
                    type: 'POST',
                    async: false,
                    url: settings.checkExisting,
                    data: { filename: file.name },
                    success: function (data) {
                        if (data == 1) {
                            var overwrite = confirm('A file with the name "' + file.name + '" already exists on the server.\nWould you like to replace the existing file?');
                            if (!overwrite) {
                                this.cancelUpload(file.id);
                                $('#' + file.id).remove();
                                if (this.queueData.uploadQueue.length > 0 && this.queueData.queueLength > 0) {
                                    if (this.queueData.uploadQueue[0] == '*') {
                                        this.startUpload();
                                    } else {
                                        this.startUpload(this.queueData.uploadQueue.shift());
                                    }
                                }
                            }
                        }
                    }
                });
            }

查看完整回答
反对 回复 2022-10-24
?
德玛西亚99

TA贡献1770条经验 获得超3个赞

上传动作我记得好像不是在onSelect里面触发的,因此即使你在onSelect里面return false;不会Break掉上传的动作。

查看完整回答
反对 回复 2022-10-24
  • 2 回答
  • 0 关注
  • 80 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信