限制Dropzone仅上传特定类型的文件 [英] Restrict Dropzone to upload only specific type of files
问题描述
我正在使用Dropzone上传文件,这是我的代码
I am uploading files with Dropzone here is my code
<div>
<form id="mainDiv" class="dropzone needsclick" enctype="multipart/form-data" method="post" action="uploadFiles?type=5" role="form">
<div class="dz-message needsclick">
Drop files here or click to upload.<br />
<span class="note needsclick">(Please upload <strong>PDF, JPG, GIF, PNG, PDF</strong> files only.)</span>
</div>
</form>
</div>
<div>
<form id="recommendationDiv" class="dropzone needsclick" enctype="multipart/form-data" method="post" action="uploadFiles?type=5" role="form">
<div class="dz-message needsclick">
Drop files here or click to upload.<br />
<span class="note needsclick">(Please upload <strong>PDF, JPG, GIF, PNG, PDF</strong> files only.)</span>
</div>
</form>
</div>
上传工作正常,但是我想限制上传文档的类型
Uploading works just fine however i want to restrict the type of upload documents
<script>
Dropzone.options.dropzone = {
acceptedFiles:'image/*'
};
</script>
接受的文件似乎无法正常工作,它只是上传了所有内容.
Accepted files doesnt seem to be working , it just uploades everything.
推荐答案
您需要添加dropzone元素的驼色ID.对于您的示例,您具有< form>
和 id ="recommendationDiv"
,因此您可以通过以下方式设置选项:
You need to include the camelized ID of the dropzone element. For your example, you have the <form>
with id="recommendationDiv"
so you would set the options with:
Dropzone.options.recommendationDiv = {
acceptedFiles: 'image/*'
};
您正在为ID为"dropzone"的表单设置不存在的选项.使用正确的ID设置后,您应该会看到正确的行为:
You are setting the options for a form with id "dropzone" that doesn't exist. After setting with the correct id, you should see the correct behavior:
请参见 Dropzone的配置文档.
这篇关于限制Dropzone仅上传特定类型的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!