在change事件里监听图片日期,若不符合条件,则中止该文件上传或删除该文件,这段代码应怎样写?
const up1 = document.getElementById('up1');
up1.addEventListener('change', getdatetimeoriginal,false);
function getdatetimeoriginal(e){
var file = e.target.files[0];
var OriginalDate;
EXIF.getData(file, function(){
OriginalDate = EXIF.getTag(this, 'DateTimeOriginal');
});
if (!CheckDate(OriginalDate)){
//中止上传
}
}
With wb.AddInputGroup("form1","ipg5","")
With .AddUploader("up1","附件(上传拍照):")
.AllowDelete = True '允许删除
.Incremental = True '允许重复选择文件或连续拍照
For Each filename as string In Filenames
If Filesys.DirectoryExists(ProjectPath & "web\" & UserName) = False Then
Filesys.CreateDirectory(ProjectPath & "web\" & UserName)
End If
If ftp.DownLoad(filename,ProjectPath & "web\" & UserName & "\" & FileSys.GetName(filename)) = True Then
.AddImage("./" & UserName & "/" & FileSys.GetName(filename))
End If
Next
End With
.AddHidenValue("Opdate0","2018-01-01")
.AddHidenValue("Dpdate0","2018-01-01")
End With
wb.AppendHTML("<script src='./lib/exif.js'></script>") '引入脚本文件
wb.AppendHTML("<script src='./lib/getexif1.js'></script>") '引入脚本文件
测试了一下,这个change事件是发生在调文件到UPLOADER图像分组框中发生的,此时还没有提交。这个过程能否中止文件调入UPLOADER分组框?
With wb.AddInputGroup("form1","ipg5","")
With .AddUploader("up1","附件(上传拍照):")
.AllowDelete = True '允许删除
.Incremental = True '允许重复选择文件或连续拍照
End With
.AddHidenValue("Opdate0","2018-01-01")
.AddHidenValue("Dpdate0","2018-01-01")
End With
wb.AppendHTML("<script src='./lib/exif.js'></script>") '引入脚本文件
wb.AppendHTML("<script src='./lib/getexif.js'></script>") '引入脚本文件
'
wb.AppendHTML("<script>up1.addEventListener('change', function(e){EXIF.getData(e.target.files[0], function() {document.getElementById('pdate').value=EXIF.getTag(this, 'DateTimeOriginal')})},false );</script>")
'
wb.AppendHTML("<script>up1.addEventListener('change', function(e){EXIF.getData(e.target.files[0], function() {document.getElementById('pdate1').value=EXIF.getTag(this, 'DateTimeDigitized')})},false );</script>")
With wb.AddButtonGroup("form1","btg1")
.Add("btn1","保存","button").Attribute ="onclick = submitForm()"
.Add("btn2","返回","button").Attribute =""
End With
function submitForm(){
show("tst1",2000);
var result = submitAjaxForm('form1','',false);
if (result =='OK') {show('dlg1')}
else if (result == 'Photo') {show('dlg3')}
else {showDialog('dlg2','错误',result)}
}
使用js变量判断
const up1 = document.getElementById('up1');
up1.addEventListener('change', getdatetimeoriginal,false);
var isupload = true;
function getdatetimeoriginal(e){
var file = e.target.files[0];
var OriginalDate;
EXIF.getData(file, function(){
OriginalDate = EXIF.getTag(this, 'DateTimeOriginal');
});
if (!CheckDate(OriginalDate)){
//中止上传
isupload = false;
}
else{isupload = true;}
}
function submitForm(){
if (isupload ){
show("tst1",2000);
var result = submitAjaxForm('form1','',false);
if (result =='OK') {show('dlg1')}
else if (result == 'Photo') {show('dlg3')}
else {showDialog('dlg2','错误',result)}
}
}
这样处理会取消所有文件的上传,能不能排除不符合要求的文件,再提交其余符合要求的文件?
试试,下面,如果不行就没有办法,只能使用第三方的上传组件,或者使用原生的file input标签自己做
if (!CheckDate(OriginalDate)){
//中止上传
e.target.files.splice(0, 1);
}