- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 dropzone 脚本,它将文件上传到某个目录。我确实已经阅读了很多文档,但仍然陷入困境。我有这个JS:
$(document).ready(function () {
Dropzone.autoDiscover = false;
var selectorElement = '.fileUploader';
var selector = $(selectorElement);
selector.addClass('dropzone');
selector.dropzone({
dictInvalidFileType: 'Kan bestand niet uploaden: ongeldige extensie.',
dictFileTooBig: 'Kan bestand niet uploaden: bestand te groot.',
dictResponseError: 'SERVER ERROR',
paramName: 'file[]', // The name that will be used to transfer the file
maxFilesize: 1000, // MB
url: 'ajax/uploadFile.php',
addRemoveLinks: true,
enqueueForUpload: true,
uploadMultiple: true,
sending: function (file, xhr, formdata) {
formdata.append('uploadPath', $(this)[0].element.dataset.uploadpath);
$(this).css({width: $(this)[0].element.getAttribute('width'), height: $(this)[0].element.getAttribute('height')});
},
init: function ()
{
var myDropzone = this;
this.on('maxfilesexceeded', function (file) {
this.removeFile(file);
});
this.on('removedfile', function (file) {
if (file.previewTemplate.children[6])
{
var filePath = this.element.dataset.uploadpath + file.previewTemplate.children[6].value;
$.post('ajax/deleteFile.php', {file: filePath}, function (response) {
CMSnotification(response.message, response.type);
}, 'JSON');
}
});
this.on('successmultiple', function (files, response) {
var responseJSON = JSON.parse(response);
CMSnotification(responseJSON.melding, responseJSON.type);
if (responseJSON.type === 'foutmelding')
{
for (var i = 0; i < files.length; i++)
{
var previewTemplate = $(files[i].previewTemplate);
previewTemplate.children('.dz-success-mark').css('display', 'none');
previewTemplate.children('.dz-error-mark').css('display', 'block');
previewTemplate.removeClass('dz-success').addClass('dz-error');
}
}
for (var i = 0; i < files.length; i++)
{
var previewTemplate = $(files[i].previewTemplate);
if (!responseJSON.files[i])
{
previewTemplate.children('.dz-success-mark').css('display', 'none');
previewTemplate.children('.dz-error-mark').css('display', 'block');
previewTemplate.removeClass('dz-success').addClass('dz-error');
}
else
{
previewTemplate.append('<input type="hidden" name="fileNames[]" value="' + responseJSON.fileNames[i] + '">');
previewTemplate.append('<input type="hidden" name="extensions[]" value="' + responseJSON.extensions[i] + '">');
}
}
});
},
accept: function (file, done) {
var extension = file.name.split('.').pop();
extension = extension.toLowerCase();
if ($.inArray(extension, window.allowedFileDropzoneExtensions) > -1) {
done();
}
else {
done('Bestands extensie niet toegestaan.');
}
}
});
});
第一个问题是,我包含此文件一次,但它仍然给出错误 dropzone已经附加。但最大的问题是:
拖放区非常不一致。对于 3 个文件,它调用 3 个请求文件。对于8个文件,可以调用4个请求文件。但它应该只调用 1。问题是,如果我允许用户在函数中提供回调作为参数并在上传成功事件中调用它,它将多次调用该回调(但它应该只调用它一次)。
最佳答案
第一个问题是因为 .ready()
函数中有语句 Dropzone.autoDiscover = false
,这会导致触发它延迟。将此语句移到 .ready()
函数之外。
Dropzone.autoDiscover = false;
$(document).ready(function () {
.........
})
第二个是由于 dropzone 的工作方式造成的,默认情况下,选项 autoProcessQueue
设置为 true,dropzone 在添加文件后立即上传文件。我认为不能保证一次上传多少个文件,但我认为默认情况下永远不会上传超过两个。
解决方案是手动触发文件的上传,为此,您需要将 autoProcessQueue
设置为 false,仅举一个示例,您可以在init
选项为触发 processQueue()
方法的按钮添加事件监听器。以下是此解决方案的示例:
html:
<button type="button" id="submit-all">Submit All</button>
js:
selector.dropzone({
autoProcessQueue: false,
uploadMultiple: true,
init: function () {
var submitButton = document.querySelector("#submit-all");
myDropzone = this;
submitButton.addEventListener("click", function () {
myDropzone.processQueue();
});
}
})
我刚刚包含了相关部分,您可以将其添加到现有配置中。这也将解决您的 successmultiple
事件问题。
关于javascript - Dropzone.js 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34288943/
我正在使用 dropzone js,它在我需要 dropzone 的页面上运行得很好。在任何其他页面上,它都会给我一个“无效的 dropzone 元素” 错误消息并导致我的其他 javascript
我已经设置了带有可点击元素的 dropzone。单击该按钮会导致 dropzone 打开文件选择器两次,而不是一次,第二次会在选择第一个文件后立即打开。 初始化代码是: Dropzone.autoDi
我正在尝试使用Dropzone.js重新创建放置的文件/文件夹的文件夹结构。 有没有办法访问每个文件的完整路径,以便可以在php端重新创建目录结构? 最佳答案 这是一种简单的方法,您可以另外发送某些文
我有一个 DropZone除了一个异常(exception),表单工作得很好,我似乎无法根据需要精确地限制文件类型。 使用 acceptedFiles: "image/*"暗淡所有不是图像的文件夹和文
我正在尝试使用 dropzone.js FAQ 以编程方式将现有图像添加到我的 dropzone作为指南: // Add the existing image if it's there. // he
我正在使用 dropzone 来处理文件上传,并且我正在使用预览容器来指定应显示上传文件的位置。 所以我的配置如下(只剩下相关部分): var myDropzone = new Dropzone("#
我想限制 Dropzone 在您单击指定的 dropzone 区域时只选择一个文件,但我找不到任何参数来执行此操作。现在,当我选择一个文件并点击打开时,Dropzone 会立即再次弹出打开文件对话框而
我想上传一个文件并根据文件大小设置宽度和高度以适应给定的 div。例如: div size: width: 600px, height: 300px img size: width: 1200px,
我正在使用 Dropzone.autoDiscover = false 并使用 element.dropzone() 创建我的放置区。我想在另一个容器中显示处理后的文件,所以我使用了 previews
我想在我的 Web 应用程序中创建一个拖放区,用于上传图像并使用 ImageMagick 操作它们。我的拖放区始终自动上传所有图像,并在拖放区中的图像预览上显示“对象对象”错误。服务器上的上传工作正常
我已经在我的 ASP.MVC 4 上成功实现了 dropzone.js。 但我需要缩短下拉区域的高度并翻译文本。 有什么简单的方法可以做到吗?我试图修改 CSS 没有结果;下拉区域仍然采用相同的高度。
在 dropzone (或vue2dropzone),有没有办法禁用文件上传并且仅**允许通过拖放添加到dropzone。 我有一个设置,我使用自定义预览模板成功地在拖放区中设置了拖放到子区域(可单击
是否可以使用外部按钮通过 Dropzone 插件添加文件?我找到了 documentation但它没有回答我的问题。确实,我无法使用诸如单击之类的处理程序事件添加文件。有解决办法吗? 最佳答案 我猜您
当我使用 dropzone 上传多个文件时,图标显示在框外。我这张图,下图中的dropzone表格是黄色的,但是当我选择很多文件时,它们会溢出并显示在表格之外。我的 dropzone 的 CSS 是
最新的 dropzone.js 版本似乎不适用于 IE11。如何测试? 1) 打开 https://www.dropzonejs.com/examples/simple.html在 IE11 2) d
我正在尝试使用Dropzone.js在我的 Laravel 网站上。 这是我的设置: index.blade.php: @csrf 在我的 app.js 文件中,我有以下代码: window.
我正在为我的网站使用 dropzone.js 并尝试在上传之前重命名文件。最近 dropzone 添加了新函数 renameFile,我无法开始工作。这是错误还是我对功能的理解有误? console.
我正在制作一个比较应用,它有两个不同的拖放区域。每个都应该像一个单独的拖放区(用于替换或删除每个图像)。 问题: var previewaDropzone = new Dropzone("div#pr
我觉得我在这里失去了理智。我已经阅读了与我的问题相关的所有线程,我添加了“Dropzone.autoDiscover = false;”但似乎没有任何效果。 我不断得到: Uncaught Error
我在我的应用程序上使用 react-dropzone,并希望在一个页面上有多个 dropzones 来预览多个图像。例如,我希望能够将英雄图像拖放到在页面顶部显示英雄图像的拖放区。然后,我想将不同的图
我是一名优秀的程序员,十分优秀!