gpt4 book ai didi

javascript - 如何让 jQuery 在上传之前选择文件时过滤文件类型?

转载 作者:行者123 更新时间:2023-11-28 04:00:16 24 4
gpt4 key购买 nike

我正在使用 jQuery-File-Upload,我想在选择时过滤文件类型。这意味着每个具有 Not Acceptable 扩展名的文件都将隐藏在文件资源管理器小部件中,用户无法看到它们。我尝试导入“acceptFileTypes”的值,但它仅在选择后验证文件类型,这不是我想要的。有人帮忙吗?

这只是我的示例代码。我无法向官方展示。对此感到抱歉。

$('#fileupload').fileupload('option', {
url: '//localhost/',
maxFileSize: 5000000,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
process: [
{
action: 'load',
fileTypes: /^image\/(gif|jpeg|png)$/,
maxFileSize: 20000000 // 20MB
},
{
action: 'resize',
maxWidth: 1440,
maxHeight: 900
},
{
action: 'save'
}
]
});

最佳答案

使用accept属性来过滤文件类型。请参阅下面我的示例代码。

<!--Code to access only for excel files-->
<input type="file" accept=".xls,.xlsx" />

关于javascript - 如何让 jQuery 在上传之前选择文件时过滤文件类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47177366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com