Skip to content
This repository was archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
设置不允许文件夹上传,只允许单文件上传,拖拽已测试
Browse files Browse the repository at this point in the history
  • Loading branch information
PSoul committed Sep 7, 2017
1 parent 9f9646d commit ca657b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
5 changes: 3 additions & 2 deletions cobra/templates/asset/js/jquery.fileupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,9 @@
}, errorHandler);
}
} else if (entry.isDirectory) {
dirReader = entry.createReader();
readEntries();
$('#progress').empty();
$('#progress').html('禁止文件夹上传!');
return;
} else {
// Return an empy list for file system items
// other than files or directories:
Expand Down
30 changes: 8 additions & 22 deletions cobra/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ <h3>Select a compressed file scan</h3>
<h4><span>Drag and drop</span> upload</h4>
<div align="center" id="selectFile"></div>
<hr>
<input type="file" class="btn_1" id="uploadFile" name="file" style="width: 100%;">
<input type="file" class="btn_1" id="uploadFile" name="file" style="width: 100%;" accept="application/bacnet-xdd+zip,.tar,.gz,.rar,.zip,.tgz,.bz2">
<br>
<small>Support for upload extensions: tar.bz2|tar|gz|tgz|tar.gz|rar|zip</small>
<small>只允许单文件上传,不允许文件夹拖拽</small>

<div id="progress">
<div class="bar"></div>
</div>
Expand All @@ -129,29 +132,11 @@ <h4><span>Drag and drop</span> upload</h4>
<script src="{{ url_for('static', filename='js/jquery.fileupload-validate.js') }}"></script>
<script>

// drag and drop upload file
// prevent browser default action
$(document).on({
dragleave: function (e) {
e.preventDefault();
},
drop: function (e) {
e.preventDefault();
},
dragenter: function (e) {
e.preventDefault();
},
dragover: function (e) {
e.preventDefault();
}
});

var fileList;
var dropbox = document.getElementById('dropbox');
var fileList = null;
dropbox.addEventListener("drop", function (e) {
e.preventDefault();
fileList = e.dataTransfer.files;
$('#selectFile').html(fileList[0].name);
});

// click and select file to upload
Expand All @@ -163,7 +148,6 @@ <h4><span>Drag and drop</span> upload</h4>
}

$(function () {

// Tab1
$("#scan").on('click', function (e) {
e.preventDefault();
Expand Down Expand Up @@ -232,8 +216,10 @@ <h4><span>Drag and drop</span> upload</h4>
url: '/api/upload',
dataType: 'json',
acceptFileTypes: /(\.|\/)(bz2|tar|gz|tgz|rar|zip)$/i,
maxNumberOfFiles: 1,
processfail: function (e, result) {
alert("不支持的文件类型")
$('#progress').empty();
$('#progress').html('文件类型错误!');
},
done: function (e, result) {
if (result.result.code === 1001) {
Expand Down

0 comments on commit ca657b5

Please sign in to comment.