jQuery FileUploadUI 单个文件上传
我正在使用 fileuploadui (https://github.com/blueimp/jQuery-File-Upload )为我的网站上传文件,但我想让它只上传到 1 个文件,而不是多个文件。
我已从输入 html 标记中删除了“多个”(输入类型=“文件”名称=“文件”),但队列仍然接受超过 1 个文件。
我的想法是,每当有人单击“浏览文件”按钮时,它都会用新文件替换当前队列。它将永远是队列中的 1 个文件。
如何使用replaceNode函数?
谢谢。
im using fileuploadui (https://github.com/blueimp/jQuery-File-Upload) to upload files for my website, but i would like to make it to upload to only 1 file, and not multiple.
i have removed "multiple" from the input html tag (input type="file" name="file"), but the queue is still accepting more than 1 file.
what i have in mind is that, whenever someone clicks on the "Browse File" button, it will replace the current queue with the new file. it will be forever 1 file in the queue.
how do i use the replaceNode function ?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
试试这个:
希望它有效^^
Try this:
Hope it works ^^
感谢@TopDev,
{% for (var i=0, file; file=o.files[i]; i++) { %}
{% $('#filelistholder').empty(); %}
Thanks to @TopDev,
<input type="file" name="files[]">
<tbody id="filelistholder" class="files">
{% for (var i=0, file; file=o.files[i]; i++) { %}
{% $('#filelistholder').empty(); %}
我在添加函数中添加了以下内容:
每次添加新文件时,这都会清除文件列表容器,确保只留下最后一个文件。
希望有帮助。
所以完整的代码如下所示:
I added the following in the add function:
This will clear the file list container every time a new file is added ensuring only the last file is left.
Hope it helps.
So the full code will look as follows:
角度和打字稿的答案(轻松适应非打字稿)。这对我有用。
在控制器(打字稿)
maxNumberOfFiles: 1 中,删除“多个”并设置 name="file" 也是不应该的。
Answer for angular and typescript (easy adapt for non typescript). This works for me.
In controller (typescript)
maxNumberOfFiles: 1, removing "multiple" and setting name="file" also was not anought.
将实际输入字段限制为单个文件上传怎么样?
What about restricting the actual input field to single file upload?
我就是这样做的:
this is how I did it: